Professional Documents
Culture Documents
Lecture#1 2
Lecture#1 2
What is a compiler?
Compiler
Assembly program
Assembler
Loader/link-editor
Intermediate
Language
Intermediate Intermediate
Language Language
Symbol
Table
Compilation Steps/Phases
• Input: result = a + b * 10
• Tokens:
NUMBER
Syntax Tree
Input: result = a + b * 10
Assign
result +
a *
b 10
Semantic Analysis
Error
Handler
Symbol
Table
Error Detection, Recovery and Reporting
• Each phase can encounter error
• Specific types of error can be detected by specific
phases
– Lexical Error: int abc, 1num;
– Syntax Error: total = capital + rate
– Semantic Error:year;
value = myarray [realIndex];
• Should be able to proceed and process the rest of the
program after an error detected
• Should be able to link the error with the source
program
Translation of a statement
result = a + b * 10
Lexical Analyzer
Symbol Table
id1 = id2 + id3 * 10
result …….
a …….
Syntax Analyzer b …….
Assign
id1 +
id2 *
id3 10
Translation of a statement
Assign
id1 +
id2 *
id3 10
Semantic Analyzer
Assign
id1 +
id2 *
id3 INTTOREAL
10
Translation of a statement
Code Generator
temp1 := INTTOREAL (10)
temp2 := id3 * temp1
temp3 := id2 + MOVF id3, R2
temp2 Id1 := temp3 MULF #10.0, R2
MOVF id2, R1
ADDF R2, R1
Code Optimizer MOVF R1, id1
Instruction Addressing
Register Mode Address
code
Relocation
bit
Syntax Analyzer