18CSC304J-Compiler Design
18CSC304J-Compiler Design
Textbook:
Alfred V. Aho, Ravi Sethi, and Jeffrey D. Ullman,
“Compilers: Principles, Techniques, and Tools”
Addison-Wesley, 1986.
error messages
Grouping of Phases:
•Analysis Phase:
Lexical, Syntax, Semantic
•Synthesis Phase:
Intermediate Code
generation, Code
optimizer, Code generator
identifier := expression
• In a parse tree, all terminals are at
leaves.
newval expression + expression
• All inner nodes are non-terminals in
identifier number a context free grammar.
oldval 12
• The type of the identifier newval must match with type of the expression (oldval+12)
• Ex:
MULT id2,id3,temp1
ADD temp1,#1,id1
• Ex:
( assume that we have an architecture with instructions whose at least one of its operands is
a machine register)
MOVE id2,R1
MULT id3,R1
ADD #1,R1
MOVE R1,id1
Back End
•Phases: Code optimizer and code generator
•Back end comprises of those phases of the compiler that are dependent
on the target machine and independent on the source language.
•This includes code optimization, code generation.
•In addition to this, it also encompasses error handling and symbol table
management operations.
Passes
•The phases of compiler can be implemented in a single pass by marking
the primary actions viz. reading of input file and writing to the output
file.
•Several phases of compiler are grouped into one pass in such a way that
the operations in each and every phase are incorporated during the pass.
•Lexical analysis, syntax analysis, semantic analysis and intermediate
code generation might be grouped into one pass. If so, the token stream
after lexical analysis may be translated directly into intermediate code.