Flow of Control .
S if E then S1 else S2
|
S.else := newlabel
|
|
S.after := newlabel
|
E.code
|
S.code = E.code ||
|
if E.place = 0 goto S.else |
gen(if E.place = 0 goto S.else) ||
|
S1 .code
|
S 1 .code ||
|
goto S.after
|
gen(goto S.after) ||
|
S.else:
|
gen(S.else :) ||
|
S 2 .code
|
gen(S.after :)
|
S.after:
|
|
|
|
In translating the if-then-else statement the Boolean expression E jumps out of it to the first instruction of the code for S1 if E is true, and to first instruction of the code for S2 if E is false, as illustrated in the figure above. As with the if-then statement, an inherited attribute s.next gives the label of the three-address instruction to be executed next after executing the code for S. An explicit goto S.next appears after the code for S1, but not after S2.
|