Professional Documents
Culture Documents
Chapter 1. Introduction
1
I. Basics
a) Terminology
Cross Compiler: a compiler that generates an object code for a machine that
e.g. compile a source in C on a PC-platform but the output (object code) runs
Linker: provides the run-time library to the object code and generates an
executable code
2
Compiler Linker
Run-Time Library
3
II. Compilation Process
a) Phases of compilation Process:
i) Lexical Analysis
ii) Syntax Analysis
iii) Intermediate Code Generation
iv) Optimization
v) Object Code Generation
i) Lexical Analysis(LA): is a phase where the source code is broken up into meaningful
units (tokens)
- overpasses comments
4
Ex. source: a := b + c:
<identifier> := <expression> ;
a
<expression> + <expression>
<identifier> <identifier>
b c
the source code is created that reflects the information uncovered during the syntax
analysis phase.
Postfix notation
Ex. a := b + c;
AST
a +
b c
3AC: t1 = b+c;
a = t1;
Postfix: abc+=
5
Ex. Source: x = a * b + c
3AC: t1 = a *b
t2 = t1 + c
x = t2
=>
t1 = a * b
x = t1 + c
v. Object Code Generation (OCG): is a phase where the IC is translated in a object code
b) Supporting Systems
During the compilation Process, we need 2 additional matters to take care of
i) Symbol Table Handler: Symbol table is the central depository of information about
names (variables, functions, types etc) created by the program. This handler inputs,
ii) Error Handler: deals with errors that may occur during the compilation.
6
c)Pass
A pass is reading one version of a program(source) from a file and writing a new version.
Ex. One Pass Compiler: reads the source and writes the object code into a file
Multiple Pass Compiler: 2 or more passes are necessary to create the object code.
Reasons: 1. Some information is NOT available during initial pass
2. NOT enough memory to hold all intermediate results
7
III. Writing a Compiler
a)Choice of a language: Any HLL can be used to write a compiler
Bootstrapping:
Pascal Compiler
Write Front Ends For Diff. Lang. Write Back ends for Diff. Machines
C PC
C++ MAC