Phases of Compiler
The compiler has a number of phases plus symbol table manager and an error
handler.
|
|
Input Source Program |
|
|
|
|
↓ |
|
|
|
|
Lexical Analyzer |
|
|
|
|
↓ |
|
|
|
|
Syntax Analyzer |
|
|
|
|
↓ |
|
|
Symbol Table Manager |
|
Semantic Analyzer |
|
Error Handler |
|
|
↓ |
|
|
|
|
Intermediate Code Generator |
|
|
|
|
↓ |
|
|
|
|
Code Optimizer |
|
|
|
|
↓ |
|
|
|
|
Code Generator |
|
|
|
|
↓ |
|
|
|
|
Out Target Program |
|
|
The cousins of the compiler are
- Preprocessor.
- Assembler.
- Loader and Link-editor.
Front End vs Back End of a Compilers. The phases of a compiler are collected
into front end and back end.
The front end includes all analysis phases end the intermediate code
generator.
The back end includes the code optimization phase and final code generation
phase.
The front end analyzes the source program and produces intermediate code
while the back end synthesizes the target program from the intermediate code.
A naive approach (front force) to that front end might run the phases
serially.
- Lexical analyzer takes the source program as an input and produces a long
string of tokens.
- Syntax Analyzer takes an out of lexical analyzer and produces a large
tree.
- Semantic analyzer takes the output of syntax analyzer and produces another
tree.
- Similarly, intermediate code generator takes a tree as an input produced
by semantic analyzer and produces intermediate code.
Minus Points
- Requires enormous amount of space to store tokens and trees.
- Very slow since each phase would have to input and output to and from
temporary disk
Remedy
- use syntax directed translation to inter leaves the actions of phases.
- Compiler construction tools.
- Parser Generators:
- The specification of input based on regular expression. The organization
is based on finite automation.
- Scanner Generator:
- The specification of input based on regular expression. The organization
is based on finite automation.
- Syntax-Directed Translation:
- It walks the parse tee and as a result generate intermediate code.
- Automatic Code Generators:
- Translates intermediate rampage into machine language.
- Data-Flow Engines:
- It does code optimization using data-flow analysis.