Compiler Lecture 3
Compiler Lecture 3
1. Phases of a Compiler
2. Practice on Different Input Expressions
3. Linker and Loader
4. Front end and Back end of a compiler
5. Symbol Table Management
6. Error Handler
Objectives and Outcomes
Objectives:
Understand the Structure of a compiler
Understand the tools involved( Scanner generator, Parser generator, etc)
Outcome:
Students will be able to represent the simulation of all phases of a compiler for
inputs.
The Phases of a Compiler
Each three address instruction has at most one operator on the right
side.
temp1 := inttofloat(60)
temp2 := id3 * temp1
temp3 := id2 + temp2
id1 := temp3
The Phases of a Compiler
So this phase optimized the code and produced the output as follows
Code Generator: The final phase of the compiler is to generate code for a
specific machine. In this phase we consider:
memory management
register assignment
MOVF R2,id3
MULF R2,#60.0
MOVF R1,id2
ADDF R1, R2
MOVF id1,R1
Reviewing the Entire Process
lexical analyzer
:=
id1 +
id2 *
id3 60
Reviewing the Entire Process
Semantic analyzer
:=
id1 +
*
id2l
id3 inttofloat
60
intermediate code generator
temp1 := inttoreal(60)
temp2 := id3 * temp1
temp3 := id2 + temp2
id1 := temp3
Reviewing the Entire Process
code optimizer
code generator
MOVF R2,id3
MULF R2,#60.0
MOVF R1,id2
ADDF R1, R2
MOVF id1,R1
Exercises
Linker: A linker, also called link editor or binder, is a program that combines the object
modules to form an executable program. In general , in case of a large program,
programmers prefer to break the code in to smaller modules, as this simplifies the
programming task. Eventually, when the source code of all the modules has been
converted in to object code, all the modules need to be put together, which is done by
the linker
Loader
Front end:
I. Lexical Analyzer
II. Syntax Analyzer
III. Semantic Analyzer
IV. Intermediate Code Generator
Back end :
V. Code Optimizer
VI. Code Generator
Advantages of Using Front-end and Back- end
A symbol table is a data structure containing all the identifiers (i.e. names of variables,
procedures etc.) of a source program together with all the attributes of each identifier.
The purpose of the symbol table is to provide quick and uniform access to identifier
attributes throughout the compilation process. Information is usually put into the symbol
table throughout the analysis phase and used for the synthesis phase.
Error Handler
Each of the six phases (but mainly the analysis phases) of a compiler can encounter
errors. On detecting an error the compiler must: