Professional Documents
Culture Documents
Software Construction and Development: Lecture-02
Software Construction and Development: Lecture-02
Construction and
Development
Lecture-02
Phases of Compilation
Process
Front-end and back-end have further components called
phases of compilation process.
Front-end:
Lexical Analysis
Syntax Analysis
Semantic Analysis
Intermediate Code Generation
Intermediate Code Optimization
Back-end:
Machine code Generation
Machine Code Optimization
Inside a
Lexical Analyzer
Compiler
Syntax Analyzer Error
listing
Source code Semantic Analyzer
Intermediate code
Generator
Intermediate code
Optimizer
Intermediate code
Machine code
Generator
Machine code
Optimizer
Machine
code
How it works
How it works – contd…
Lexical Analysis (Scanning)
Source Stream
code
Lexical Analyzer of
tokens
Lexical errors
Lexical Analyzer (Scanner)
Stream of
Source tokens Parse tree
code Lexical Analyzer Syntax Analyzer
Syntax errors
Syntax Analyzer (Parser)
X Y
a a X
a b
Parser can only construct Parse tree if tokens are valid
and in right sequence.
For example, input baab cannot be constructed from
the same CFG.
Semantic Analysis
Symbol table
Parse Annotated
tree
Semantic Analyzer parse tree
Semantic errors
Semantic Analyzer
Dynamic Semantics:
Must be checked at run-time.
Example, a char value being input to an int
variable at run-time.
Compiler does not do dynamic semantic checking; it
generates code to check static semantics.
Symbol Table
Example:
void main() { a = 5; }
void func1()
{ int x; }
void main()
{ int s = x; }
void func1()
{ ……. }
void main()
{ func1(2); ……. }
Annotated Parse Tree