Professional Documents
Culture Documents
Compiler Construction
Compiler Construction
Compiler Construction
Introduction, (Part-II)
by Safdar Hussain
Topics
• The Analysis Task for Compilation (Lexical, Hierarchical & Semantic Analysis)
• Supporting Phases (Symbol Table & Error Handler), The Synthesis task, Compilation process
• Loaders & Link Editors, Grouping of phases, Compiler Construction Tools
The Analysis Task for Compilation
• Three Phases:
– Linear / Lexical Analysis:
• L-to-R Scan to Identify Tokens
token: sequence of chars having a collective meaning
– Hierarchical Analysis:
• Grouping of Tokens Into Meaningful Collection
– Semantic Analysis:
• Checking to ensure Correctness of Components
For
Example:
Position := initial + rate * 60 ;
_______ __ _____ _ ___ _ __ _
expression is an (expression), or
expression + expression, or
expression * expression, or
number, or
identifier, or ...
Safdar Hussain, Khwaja Fareed University, RYK 5
Why Have We Divided Analysis in This Manner?
Lexical Analysis
• Scans Input, Its Linear Actions Are Not Recursive
• Identify Only Individual “words” that are the the Tokens of the
Language
:= :=
position + position +
initial * initial *
60
• Error Handling
– Detection of Different Errors Which Correspond to All
Phases
– What Kinds of Errors Are Found During the Analysis
Phase?
– What Happens When an Error Is Found?
lexical analyzer
id1 := id2 + id3 * 60
syntax analyzer
:=
id1 +
id2 *
id3 60
semantic analyzer
:=
Symbol + E
Table
id1 r
id2 *
r
position .... id3 inttoreal o
60 r
initial …. s
intermediate code generator
rate….
Number of Passes:
A pass: requires r/w intermediate files
17