S while E do S1
|
S.begin := newlabel
|
S. begin :
|
S.after := newlabel |
E.code
|
|
if E.place = 0 goto S.after |
S.code := gen(S.begin:) || |
S1 .code
|
E.code ||
|
goto S.begin
|
gen(if E.place = 0 goto S.after) ||
|
S.after :
|
S 1 .code ||
|
|
gen(goto S.begin) ||
|
|
gen(S.after:)
|
|
|
|
The syntax directed definition is shown in the slide. A new label S .begin is created and attached to the first instruction for E. Another new label S. after is created. The code for E generates a jump to the label if E is true, a jump to S.next if E is false; again, we set E.false to be S.next. After the code for S1 we place the instruction goto S.begin, which causes a jump back to the beginning of the code for the Boolean expression. Note that S1.next is set to this label S.begin, so jumps from within S1.code can directly to S.begin.
|