THREE-ADDRESS CODES are a form of IR similar to assembler for an imaginary machine. Each three address code instruction has the form
x := y op z
t1 := y + z t2 := x + t1
THREE-ADDRESS STATEMENTS are similar to assembly code. We will consider the following statements.
goto Lwhere L is a symbolic label of a statement.
if x relop y goto Lwhere statement L is executed if x and y are in relation relop.
param x1 param x2 param xn call p, ncorresponding to the procdure call p(x1, x2, ..., xn)
SYNTAX-DIRECTED TRANSLATION INTO 3-ADDRESS CODE. We give below a S-definition generating 3-address code from assignments. We use the following attributes
Production | Semantic Rule |
S ![]() ![]() |
S.code :=
E.code | | generate(
![]() |
E ![]() |
E.place := newtemp |
code := generate(E.place, ':=', E1.place, '+', E2.place) | |
E.code := E1.code | | E2.code | | code | |
E ![]() |
E.place := newtemp |
code := generate(E.place, ':=', E1.place, '*', E2.place) | |
E.code := E1.code | | E2.code | | code | |
E ![]() |
E.place := newtemp |
code := generate(E.place, ':=', '
![]() |
|
E.code := E1.code | | code | |
E ![]() |
E.place := E1.place |
E.code := E1.code | |
E ![]() ![]() |
E.place :=
![]() |
E.code := '' |