



















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!




















CSC434 - Compiler Construction Department of Mathematics and Computer Science, SLU 2020/
Is a program which translates the source form of a program (written in HLL) into a semantically equivalent target form (MLL).
A multi-pass compiler does one ‘simple’ thins at once and passes its output to the next stage
lex (lexical analysis) Converts a stream of characters into a stream of tokens syn (syntax analysis) Also called parsing. Converts a stream of tokens into a parse tree – a.k.a. (abstract) syntax tree trans (translation/linearization) Or intermediate code generation, converts a tree into simple (linear) intermediate code cg (target code generation) Translates intermediate code into target machine program. At this stage, optimization is done to reduce length of machine language program.
INTERMEDIATE LANGUAGES Three approaches to intermediate representation:
Syntax tree: Depicts the natural hierarchical structure of a source program. A dag (Directed Acyclic Graph) gives similar information in a more compact way because common subexpressions are identified. Example: The following is a syntax tree and dag for assignment statement a := b * -c + b -c*
Three-Address Code: Is a sequence of statements of a general form x := y op z
Advantages of three-address code
“three-address code” reason: because each statement usually contains three addresses, two for the operands and one for the result Types of three-address statements:
Here, each node is represented as a record with a field for its operator and additional fields for pointers to its children
Syntax-directed translation into three-address code: When three-address code is generated, temporary names are made up for the interior nodes of a syntax tree. E.g. id:=E consists of code to evaluate E into temporary t , then assignment id .place := t