Syntax-Directed Translation into Three-Address Code: Production Semantic Rules S->id:=E S.code := E.code || gen(id.place E.place) ‘:=’ E->E1+E2 E.place := newtemp; E.code :=E1.code || E2.code || gen(E.place E1.place E2.place) ‘:=’ ‘+’ E->E1*E2 E.place := newtemp; E.code := E1.code || E2.code || E1.place E2.place) ‘:=’ ‘*’ E->-E1 := newtemp; E.code :=E1.code || gen(E.place E1.place) ‘:=’ ‘uminus’ E->( E1 ) E.place := E1.place; E.code := E1.code; E->id E.place := id.place; E.code := “” Implementation of Three-Address Statements: Eg. a := b * -c + b * -c Quadruples:(easy to rearrange code for global optimization, lots of temporaries) # Op Arg1 Arg2 Res (0) uminus c t1 (1) * b t1 t2 (2) uminus c t3 (3) * b t3 t4 (4) + t2 t4 t5 (5) := t5 a Triples: (temporaries are implicit, difficult to rearrange code) # Op Arg1 Arg2 (0) uminus c (1) * b (0) (2) uminus c (3) * b (2) (4) + (1) (3) (5) := a (4) Indirect Triples: (temporaries are implicit & easier to rearrange code.
Syntax-Directed Translation into Three-Address Code: Production Semantic Rules S->id:=E E->E1+E2 E->E1*E2 E->-E1 E->( E1 ) E->id S.code := E.code || gen(id.place ‘:=’ E.place) E.place := newtemp; E.code :=E1.code || E2.code || gen(E.place ‘:=’ E1.place ‘+’ E2.place) E.place := newtemp; E.code := E1.code || E2.code || ‘:=’ E1.place ‘*’ E2.place) := newtemp; E.code :=E1.code || gen(E.place ‘:=’ ‘uminus’ E1.place) E.place := E1.place; E.code := E1.code; E.place := id.place; E.code := “” Implementation of Three-Address Statements: Eg. a := b * -c + b * -c Quadruples:(easy to rearrange code for global optimization, lots of temporaries) # Op Arg1 Arg2 Res (0) uminus c t1 (1) * b t1 t2 (2) uminus c t3 (3) * b t3 t4 (4) + t2 t4 t5 (5) := t5 a Triples: (temporaries are implicit, difficult to rearrange code) # Op Arg1 Arg2 (0) uminus c (1) * b (0) (2) uminus c (3) * b (2) (4) + (1) (3) (5) := a (4) Indirect Triples: (temporaries are implicit & easier to rearrange code.
1%29Compiler.docx