









Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!










2
Three-address code is attractive for several reasons:
4
absence of destructive operators gives the compiler freedom to reuse names and values three-address code is reasonably compact: operations are 1 to 2 bytes; addresses are 4 bytes
5
many modern processors implement three-address operations, a three-address code models their properties well
7
We now consider syntax- directed translation schemes using three-address code for various programming constructs
We start with the assignment statement
8
Production translation scheme S → id = E { p = lookup(id.name); emit( p, ‘=’, E.place); }
E → E 1 + E 2 { E.place = newtemp(); emit( E.place, ‘=’, E 1 .place, ‘+’, E 2 .place); }
E → E 1 ∗ E 2 { E.place = newtemp(); emit( E.place, ‘=’, E 1 .place, ‘∗’, E 2 .place); }
10
The tranlation scheme uses a symbol table for identifiers and temporaries
Every time the parser encounters an identifier, it installs it in the symbol table.
11
The tranlation scheme uses a symbol table for identifiers and temporaries
Every time the parser encounters an identifier, it installs it in the symbol table.
13
The routine lookup(name)
checks if there an entry for the name in the symbol table
If the name is found, the
routine returns a pointer to entry.
14
The routine lookup(name)
checks if there an entry for the name in the symbol table
If the name is found, the
routine returns a pointer to entry.
16
The routine emit()
generates a three-address statement which can either be held in memory or written to a file
17
Example
Here is the bottom-up parse of the assignment statement
a = b-c + b-c**
and the syntax-directed translation into three-address code