Production | Semantic Rule |
S E S1 | E.true := newlabel |
E.false := S.next | |
S1.next := S.next | |
S.code := E.code | | generate(E.true ':') | | S1.code | |
S E S1 S2 | E.true := newlabel |
E.false := newlabel | |
S1.next := S.next | |
S2.next := S.next | |
code1 := E.code | | generate(E.true ':') | | S1.code | |
code2 := generate('goto' S.next) | | | |
code3 := generate(E.false ':') | | S2.code | |
S.code := code1 | | code2 | | code3 | |
S E S1 | S.begin := newlabel |
E.true := newlabel | |
E.false := S.next | |
S1.next := S.begin | |
code1 := generate(S.begin ':') | | E.code | |
code2 := generate(E.true ':') | | S1.code | |
code3 := generate('goto' S.begin) | |
S.code := code1 | | code2 | | code3 |
for ( s1 ; e ; s2 ) s3Taking its meaning to be
s1; while ( e ) { s3 ; s2 ; }construct a syntax-directed definition to translate C-style for-statements into three-address code.