










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
prog : expr { cout << $1 << endl;} ;
expr : expr PLUS expr {$$ = $1 + $3;} | expr MINUS expr {$$ = $1 - $3;} | expr TIMES expr {$$ = $1 * $3;} | expr DIVIDE expr {if($3) $$ = $1 / $3;} | LPAREN expr RPAREN {$$ = $2;} | MINUS expr {$$ = -$2;} | NUMBER {$$ = $1;} ; %%
$$ $
Docsity.com
4
prog : expr { cout << $1 << endl;} ; expr : expr PLUS expr {$$ = $1 + $3;} | expr MINUS expr {$$ = $1 - $3;} | expr TIMES expr {$$ = $1 * $3;} | expr DIVIDE expr {if($3) $$ = $1 / $3;} | LPAREN expr RPAREN {$$ = $2;} | MINUS expr {$$ = -$2;} | NUMBER {$$ = $1;} ; %%
5
E
E E
val=
val=
E val=
val=
E val=
7
Compilers are organized as a series of passes
This creates the need for an intermediate representation for the code being compiled
8
Compilers are organized as a series of passes
This creates the need for an intermediate representation for the code being compiled
10
Compilers use some internal form– an IR –to represent the code being analysed and translated
Many compilers use more than one IR during the course of compilation
11
The IR must be expressive enough to record all of the useful facts that might be passed between passes of the compiler
13
During translation, the compiler derives facts that have no representation in the source code
For example, the addresses of variables and procedures
14
Typically, the compiler augments the IR with a set of tables that record additional information
These tables are considered part of the IR
16
Selecting an appropriate IR for a compiler project requires an understanding of both the source language and the target machines and the properties of the programs to be compiled
17
Thus, a source-to-source translator might keep its internal information in a form quite to close to the source