1. NETAJI SUBASH ENGINEERING COLLEGE
PHASES OF COMPILER DESIGN
Name: AJIT YADAV
University Roll No. : 10900220033
Class Roll No.:33
Sec : A
Stream : IT
Registration No.:201090100210082
2. What is compiler?
Compiler is a program which
takes one language as input and
translate it into an equivalent
another language.
Compiler is divided into two parts:
Analysis and Synthesis
3. Phases of compiler
Conceptually, a compiler operates into phases, each
of which transform the source program from one
representation to another.
Each phase takes input from its previous stage, has
its own representation of source program, and
feeds its output to the next phase of the compiler.
The compiler has six phases called as lexical
analyzer, syntax analyzer, semantic analyzer,
intermediate code generator, code optimizer and
code generator.
Two other activities, symbol-table management
and error handling, are interacting with the six
phases of compiler.
4. Lexical analysis
The lexical analysis is also known
as scanning.
It is the phase of compilation in
which the complete source code
is scanned and source program is
broken up into group of strings
called token.
A token is sequence of character
having a collective meaning.
E.g. Total = count + rate
After lexical analysis, the statement
is broken up into series of tokens
as follows:
identifier total, assignment operato
r, identifier count, plus sign,
identifier rate
syntax analysis
The syntax analysis is also
known as parsing.
In this phase token generated
by lexical analysis are grouped
together to form a hierarchical
structure known as syntax tree.
5. semantic analysis
• Once syntax is checked in the syntax
analyzer phase the next phase
i.e. semantic analyzer determines the
meaning of the source string.
• For example meaning of source string
means matching parenthesis, matching
if…else statement, performing arithmetic
operation of expression that are type
compatible or checking operation scope.
Code optimization
The code optimization phase attempt to
improve the intermediate code
This is necessary to have a faster executing
code or less consumption of memory
Thus, by optimizing the code the overall
running time of the target program can be
improved.
Intermediate code generation
The intermediate code is a kind of
code which is easy to generate
and this code can be easily
converted to target code.
This code is in variety of form
such as three address code,
quadruple, triple, posix.
Code generation
• In this phase, target code is generated.
•The Intermediate code instructions are
translated into sequence of machine
instruction