Chapter 1.1
Chapter 1.1
Compiler Construction
Code No. : CS-366
CHAPTER 1: INTRODUCTION
1.1 Definition of Compiler, Aspects of compilation.
1.2 The structure of Compiler.
Lexical Analysis,
Syntax Analysis,
Semantic Analysis,
Intermediate Code generation,
code optimization,
code generation.
1.4 Error Handling
a. Analysis Phase :
An intermediate representation is created
from the give source code :
i. Lexical Analyser
ii. Syntax Analyser
iii. Semantic Analyser
iv. Intermediate Code Generator
b. Synthesis Phase :
Equivalent target program is
created from the intermediate representation.
It has two parts :
i. Code Optimizer
ii. Code Generator
From the above diagram, all phases are managed by symbol
table manager.
In symbol table manager, information is stored which is related
to symbols.
The errors which occur during all phases are handled by error
handler.
Lexical analyser divides the program into “tokens”, Syntax
analyser recognizes “sentences” in the program using syntax
of language and Semantic analyser checks static semantics of
each construct.
Intermediate Code Generator generates “abstract” code.
a. Analysis Phase:
i. Lexical Analyser :
It is also called scanner.
A program that does the task of lexical analysis is
called lexical analyser.
Lexical analyser generates a token and blank
characters are eliminated.
Ex.
Sum = a + b;
a = int
b= char
Sum = double
Intermediate Code Generator :
It is a bridge between
analysis and synthesis phase.
It generates intermediate code, that is a form which
can be readily executed by machine.
We have many popular intermediate codes.
i. Code Optimization :
It improves the intermediate code.
Code optimization takes less memory space and less
execution time without changing the functionality or
correctness.
It improves efficiency of the program.
Ex.
First Pass: is refers as
(a) Front end
(b) Analytic part
(c) Platform independent
In first pass the included phases are as Lexical analyser, syntax
analyser, semantic analyser, intermediate code generator are
work as front end and analytic part means all phases analyse
the High level language and convert them three address
code and first pass is platform independent because the output
of first pass is as three address code which is useful for every
system and the requirement is to change the code optimization
and code generator phase which are comes to the second
pass.
Second Pass: is refers as
(a) Back end
(b) Synthesis Part
(c) Platform Dependent
In the first pass, compiler can read the source program, scan it,
extract the tokens and store the result in an output file.
In the second pass, compiler can read the output file produced by
first pass, build the syntactic tree and perform the syntactical
analysis. The output of this phase is a file that contains the
syntactical tree.
In the third pass, compiler can read the output file produced by
second pass and check that the tree follows the rules of language or
not. The output of semantic analysis phase is the annotated tree
syntax.
This pass is going on, until the target output is produced.
Cross Compiler:
Cross compiler that runs on a
machine „A‟ and produces a code for another machine
„B‟.
It is capable of creating code for a platform other than
the one on which the compiler is running.
Bootstrapping:
Bootstrapping is a process in which
simple language is used to translate more complicated
program which in turn may handle for more
complicated program.
This complicated program can further handle even
more complicated program and so on.
Boot strapping is used to produce self hosting
compiler.
It is a compiler that can compile its own source code.
Step-2: Then using with small subset of C i.e. C0, for the
source language c the compiler is written.
Step-3: Finally we compile the second compiler. using
compiler 1 the compiler 2 is compiled.