SlideShare a Scribd company logo
1 of 55
Jeena Thomas, Asst Professor, CSE, SJCET Palai
1
» Phases of a compiler
» Analysis and synthesis phases
Jeena Thomas, Asst Professor, CSE, SJCET Palai
2
» A compiler is a kind of translator.
TRANSLATORSoftware that accepts text in
certain language
(SOURCE LANGUAGE)
Text in another language
,preserving the meaning
of text
(TARGET/OBJECT
LANGUAGE)
Jeena Thomas, Asst Professor, CSE, SJCET Palai
3
» A translator, is a generalized form of compiler.
» When the object language is a low level language,
such a translator is called a compiler.
» This conversion process is essential for the hardware
to interpret and perform the semantics of the input
program.
» As an important part of this translation process, the
compiler reports to its user the presence of errors in
source program.
Jeena Thomas, Asst Professor, CSE, SJCET Palai
4
Jeena Thomas, Asst Professor, CSE, SJCET Palai
5
» Compiler is a program written in source language and
translates it into an equivalent target language.
Jeena Thomas, Asst Professor, CSE, SJCET Palai
6
» Source code
» a=(b+c)*(b+c)*2
Target code
MOV b,R2
ADD R2,c
MUL R2,R2
MUL R2, #2.0
MOV R2,a
7
Jeena Thomas, Asst Professor, CSE, SJCET Palai
» FORTRAN compilers of the late 1950s
» 18 person-years to build
8
Jeena Thomas, Asst Professor, CSE, SJCET Palai
» Writing a compiler gives a student experience with large-
scale applications development. Your compiler program may
be the largest program you write as a student. Experience
working with really big data structures and complex
interactions between algorithms will help you out on your
next big programming project.
» Compiler writing is one of the shining triumphs of CS theory.
It demonstrates the value of theory over the impulse to just
"hack up" a solution.
» Compiler writing is a basic element of programming
language research. Many language researchers write
compilers for the languages they design.
» Many applications have similar properties to one or more
phases of a compiler, and compiler expertise and tools can
help an application programmer working on other projects
besides compiler
Jeena Thomas, Asst Professor, CSE, SJCET Palai
9
» Throughout the 1950’s, compilers were considered
difficult programs to write.
» The first Fortan compiler took 18 staff-years o
implement.
» Good implementation languages, programming
environments, and software tool has been
developed as the systematic techniques for
handling many of important tasks that occur
during compilation.
» With these advances, a substantial compiler can be
implemented even as a student project in a one-
semester compiler-design course.
Jeena Thomas, Asst Professor, CSE, SJCET Palai
10
» is more broadly applicable and has been
employed in rather unexpected areas.
» Text-formatting languages, preprocessor
packages
» Silicon compiler for the creation of VLSI circuits
» Command languages of OS
» Query languages of Database systems
11
Jeena Thomas, Asst Professor, CSE, SJCET Palai
» Hierarchy of operations to be maintained
-to determine the correct order of evaluation of
the expressions.
 Maintaining data type integrity
-each part of complex expression can be made of
different types.
 Compiler as prior knowledge about the nature of
user defined data types.
- struct, enum, union,
 Appropriate storage mappings for data structures
- allocation of memory for data
Jeena Thomas, Asst Professor, CSE, SJCET Palai
12
» The compiler must resolve the occurrence of
each variable name in a program to determine
the name space to which a referenced variable
belongs to.(Symbol table)
» Compiler should have facilities to handle different
control structures like ‘if-then-else’, ‘for’, ‘while’
etc. The compiler should have the facilities to
increment the loop variable and terminate the
loop.
13
Jeena Thomas, Asst Professor, CSE, SJCET Palai
» Process of compilation is highly complex, it is split
into a series of subprocesses called phases.
» A phase is a logically cohesive operation that takes
as input one representation of source program and
produces as output another representation.
» Activities of compilation split into two parts
1) Analysis part
2) Synthesis part
14
Jeena Thomas, Asst Professor, CSE, SJCET Palai
15
Jeena Thomas, Asst Professor, CSE, SJCET Palai
» Analysis of source program
» is done by the front end of compiler
» It determines meaning of source string.
» Synthesis of target program
» Is done by the back end of the compiler.
» An equivalent target string is constructed from
the output given by the front end of compiler.
16
Jeena Thomas, Asst Professor, CSE, SJCET Palai
» In compiling, analysis has three phases:
» Linear analysis: stream of characters read from
left-to-right and grouped into tokens; known as
lexical analysis or scanning
» Hierarchical analysis: tokens grouped
hierarchically with collective meaning; known
as parsing or syntax analysis
» Semantic analysis: check if the program
components fit together meaningfully
17
Jeena Thomas, Asst Professor, CSE, SJCET Palai
» Optimization of code
» Allocation of memory
» Generation of code
18
Jeena Thomas, Asst Professor, CSE, SJCET Palai
Jeena Thomas, Asst Professor, CSE, SJCET Palai
19
20
Jeena Thomas, Asst Professor, CSE, SJCET Palai
» Performs the linear analysis on the source
program.
» It reads a stream of characters making up the
source program from left to right and groups them
into tokens.
» A token is defined as a sequence of characters that
have a collective meaning.
» For each token identified, this phase also
determines the category of the token as identifier,
constant or reserved words and its attribute that
identifies the symbol’ position in the symbol table
21
Jeena Thomas, Asst Professor, CSE, SJCET Palai
22
Jeena Thomas, Asst Professor, CSE, SJCET Palai
» Identifiers are names of variables, constants,
functions, data types, etc.
» Store information associated with identifiers
» Information associated with different types of
identifiers can be different
» Information associated with variables are
name, type, address, size (for array), etc.
» Information associated with functions are name
, type of return value, parameters, address, etc.
23
Jeena Thomas, Asst Professor, CSE, SJCET Palai
» Consider the following statement
» a=(b+c)*(b+c)*2--------------------------------(1)
24
Jeena Thomas, Asst Professor, CSE, SJCET Palai
Symbol Category Attribute
a Identifier #1
= operator Assignment(1)
b Identifier #2
+ operator Arithmetic(1)
c Identifier #3
* operator Arithmetic(2)
( operator Open parenthesis(1)
) operator Closed parenthesis(1)
2 Constant #4
25
Jeena Thomas, Asst Professor, CSE, SJCET Palai
» This phase performs hierarchical analysis on the
source program.
» Here, the tokens are grouped into hierarchically
nested collections with collective meaning called
expressions or statements.
» It determines structure of source language.
» Represents the grammar / syntax of the language.
» These grammatical phrases are represented in the
form of parse tree.
26
Jeena Thomas, Asst Professor, CSE, SJCET Palai
» Describes the syntactic structure of input
» The terminal nodes represent the tokens and
interior nodes represent the expressions.
27
Jeena Thomas, Asst Professor, CSE, SJCET Palai
» Syntactic structures also represented using syntax
trees.
» A syntax tree is a compressed representation of
the parse tree, where the operators appear as
interior nodes and operands for this operator as
their children
28
Jeena Thomas, Asst Professor, CSE, SJCET Palai
» Syntax tree is a compressed representation of a
parse tree.
» The interior node in a syntax tree represent an
operator, whereas the interior nodes in a parse
tree represent an expression.
» The leaf node of a syntax tree represent the
operand, whereas leaf node in a parse tree
represent the tokens.
29
Jeena Thomas, Asst Professor, CSE, SJCET Palai
» Goal- is to determine the meaning of a source
string.
» It checks the source program for semantic errors
and gathers the type of information that can be
used in subsequent phases of compilation.
» Type checking for operations also performed
during this phase.
» Output- Annotated tree
30
Jeena Thomas, Asst Professor, CSE, SJCET Palai
» It is a part of the synthesis process of the
compiler.
» The intermediate code is the representation for
an abstract machine.
» Using the intermediate code, optimization and
code generation can be performed.
31
Jeena Thomas, Asst Professor, CSE, SJCET Palai
» It should be easily generated from semantic
representation of the source program.
» It should be easy to translate the intermediate
code to target language.
» It should be capable of holding the values
computed during translation.
» It should maintain precedence ordering of the
source language.
» It should be capable of holding the correct number
of operands of the instruction.
32
Jeena Thomas, Asst Professor, CSE, SJCET Palai
» T1=intoreal(2)
» T2=b+c
» T3=b+c
» T4=T2*T3
» T5=T4*T1
» a=T5
33
Jeena Thomas, Asst Professor, CSE, SJCET Palai
» The main aim of this phase is to improve on the
intermediate code to generate a code that runs
faster and/or occupies less space.
» It is used to establish trade off between
compilation speed and execution speed.
34
Jeena Thomas, Asst Professor, CSE, SJCET Palai
» T1=inttoreal(2)
» T2=b+c
» T3=T2*T2
» T4=T3*T1
» a=T4
35
Jeena Thomas, Asst Professor, CSE, SJCET Palai
» The main aim of this phase is to allocate storage
and generate a relocatable machine/ assembly
code.
» Memory locations and registers are allocated for
variables.
» The instructions in intermediate code format are
converted into machine instructions.
36
Jeena Thomas, Asst Professor, CSE, SJCET Palai
» MOV R2, b
» ADD R2,c
» MUL R2,R2
» MUL R2, #2.0
» MOV R2, a
37
Jeena Thomas, Asst Professor, CSE, SJCET Palai
» The compiler also attempts to improve the target
code generated by the code generator by choosing
proper addressing modes to improve the
performance, replacing slow instructions by fast
ones and eliminating redundant instructions.
» MUL R2, #2.0-------------------SHL(Shift Left
Instruction)
38
Jeena Thomas, Asst Professor, CSE, SJCET Palai
» MOV b, R2
» ADD R2,c
» MUL R2,R2
» SHL R2
» MOV R2, a
39
Jeena Thomas, Asst Professor, CSE, SJCET Palai
» 1.)Symbol Table Management
» 2.) Literal Table Management
» 3.) Error Detection and Reporting
40
Jeena Thomas, Asst Professor, CSE, SJCET Palai
» A symbol table is a data structure that contains a
record for each identifier with fields for the
attributes of the identifier.
» This data structure has facilities to
manipulate(add/delete) the elements in it.
» The type information about the identifier is
detected during lexical analysis phase and is
entered into the symbol table.
» This information is used during the intermediate
code generation and code generation phases of
compiler to verify type information.
41
Jeena Thomas, Asst Professor, CSE, SJCET Palai
42
Jeena Thomas, Asst Professor, CSE, SJCET Palai
Address Symbol Attribute Memory Location
1 A id,real 1000
2 B id,real 1100
3 C id,real 1110
» literal table maintains the details of constants
and strings used in the program.
» It reduces the size of a program in memory by
allowing reuse of constants and strings.
» It is also needed by the code generator to
construct symbolic addresses for literals.
43
Jeena Thomas, Asst Professor, CSE, SJCET Palai
Address Literal Attribute Memory Location
4 2 const,int 1200
44
Jeena Thomas, Asst Professor, CSE, SJCET Palai
» Each phase encounters errors.
» After detecting the errors, this phase must deal
with the errors to continue with the process of
compilation.
45
Jeena Thomas, Asst Professor, CSE, SJCET Palai
» 1. Lexical analyzer: Misspelled tokens
» 2.Syntax analyzer: syntax errors like missing
parenthesis
» 3.Intermediate code generator: Incompatible
operands for an operator
» 4. Code Optimizer: Unreachable statements
» 5. Code Generator :Memory restrictions to store a
variable. For example, when the value of an
integer variable exceeds its size.
» Symbol tables: Multiply declared identifiers
46
Jeena Thomas, Asst Professor, CSE, SJCET Palai
» Show the output of all the phases of he
compiler for the following line o code
» A[index]=4+2+index
47
Jeena Thomas, Asst Professor, CSE, SJCET Palai
48
Jeena Thomas, Asst Professor, CSE, SJCET Palai
49
Jeena Thomas, Asst Professor, CSE, SJCET Palai
» Scanner generators
» Parser generators
» Syntax-directed translation engines
» Automatic code generators
» Data-flow engines
50
Jeena Thomas, Asst Professor, CSE, SJCET Palai
» Scanner generators:
» generate lexical analyzers automatically from
the language specifications written using
regular expressions.
» It generates a finite automaton to recognize the
regular expression.
» Example-lex
51
Jeena Thomas, Asst Professor, CSE, SJCET Palai
» parser generators
» They produce syntax analyzers from Context
Free Grammar(CFG).
» As syntax analysis phase is highly complex and
consumes manual and compilation time, these
parser generators are highly useful.
» Example-yacc
52
Jeena Thomas, Asst Professor, CSE, SJCET Palai
» Syntax-directed translation engines
» These engines have routines to traverse the
parse tree and produce intermediate code.
» The basic idea is that one or more translations
are associated with each node of parse tree.
53
Jeena Thomas, Asst Professor, CSE, SJCET Palai
» Automatic code generators
» These tools convert the intermediate language
into machine language for the target machine
using a collection of rules.
» Template matching process is used.
» An intermediate language statement is replaced
by its equivalent machine language statement
54
Jeena Thomas, Asst Professor, CSE, SJCET Palai
» Data-flow engines
» It is used in code optimization.
» These tools perform good code optimization
using “data-flow analysis” which gathers
information that flows from one part of the
program to another.
55
Jeena Thomas, Asst Professor, CSE, SJCET Palai

More Related Content

What's hot

Code optimization in compiler design
Code optimization in compiler designCode optimization in compiler design
Code optimization in compiler designKuppusamy P
 
Lexical Analysis - Compiler Design
Lexical Analysis - Compiler DesignLexical Analysis - Compiler Design
Lexical Analysis - Compiler DesignAkhil Kaushik
 
Techniques & applications of Compiler
Techniques & applications of CompilerTechniques & applications of Compiler
Techniques & applications of CompilerPreethi AKNR
 
Lexical Analysis - Compiler design
Lexical Analysis - Compiler design Lexical Analysis - Compiler design
Lexical Analysis - Compiler design Aman Sharma
 
Error Detection & Recovery
Error Detection & RecoveryError Detection & Recovery
Error Detection & RecoveryAkhil Kaushik
 
Chomsky classification of Language
Chomsky classification of LanguageChomsky classification of Language
Chomsky classification of LanguageDipankar Boruah
 
Introduction to Compiler Construction
Introduction to Compiler Construction Introduction to Compiler Construction
Introduction to Compiler Construction Sarmad Ali
 
Introduction TO Finite Automata
Introduction TO Finite AutomataIntroduction TO Finite Automata
Introduction TO Finite AutomataRatnakar Mikkili
 
DESIGN AND ANALYSIS OF ALGORITHMS
DESIGN AND ANALYSIS OF ALGORITHMSDESIGN AND ANALYSIS OF ALGORITHMS
DESIGN AND ANALYSIS OF ALGORITHMSGayathri Gaayu
 
Type checking in compiler design
Type checking in compiler designType checking in compiler design
Type checking in compiler designSudip Singh
 
Structure of the compiler
Structure of the compilerStructure of the compiler
Structure of the compilerSudhaa Ravi
 

What's hot (20)

Code optimization in compiler design
Code optimization in compiler designCode optimization in compiler design
Code optimization in compiler design
 
Lexical Analysis - Compiler Design
Lexical Analysis - Compiler DesignLexical Analysis - Compiler Design
Lexical Analysis - Compiler Design
 
Techniques & applications of Compiler
Techniques & applications of CompilerTechniques & applications of Compiler
Techniques & applications of Compiler
 
Lexical Analysis - Compiler design
Lexical Analysis - Compiler design Lexical Analysis - Compiler design
Lexical Analysis - Compiler design
 
Error Detection & Recovery
Error Detection & RecoveryError Detection & Recovery
Error Detection & Recovery
 
Chomsky classification of Language
Chomsky classification of LanguageChomsky classification of Language
Chomsky classification of Language
 
Introduction to Compiler design
Introduction to Compiler design Introduction to Compiler design
Introduction to Compiler design
 
Phases of compiler
Phases of compilerPhases of compiler
Phases of compiler
 
Phases of Compiler
Phases of CompilerPhases of Compiler
Phases of Compiler
 
Introduction to Compiler Construction
Introduction to Compiler Construction Introduction to Compiler Construction
Introduction to Compiler Construction
 
Daa notes 1
Daa notes 1Daa notes 1
Daa notes 1
 
MACRO PROCESSOR
MACRO PROCESSORMACRO PROCESSOR
MACRO PROCESSOR
 
Introduction TO Finite Automata
Introduction TO Finite AutomataIntroduction TO Finite Automata
Introduction TO Finite Automata
 
Compiler Chapter 1
Compiler Chapter 1Compiler Chapter 1
Compiler Chapter 1
 
DESIGN AND ANALYSIS OF ALGORITHMS
DESIGN AND ANALYSIS OF ALGORITHMSDESIGN AND ANALYSIS OF ALGORITHMS
DESIGN AND ANALYSIS OF ALGORITHMS
 
Type checking in compiler design
Type checking in compiler designType checking in compiler design
Type checking in compiler design
 
Role-of-lexical-analysis
Role-of-lexical-analysisRole-of-lexical-analysis
Role-of-lexical-analysis
 
Structure of the compiler
Structure of the compilerStructure of the compiler
Structure of the compiler
 
COMPILER DESIGN
COMPILER DESIGNCOMPILER DESIGN
COMPILER DESIGN
 
Code Optimization
Code OptimizationCode Optimization
Code Optimization
 

Viewers also liked

Compiler Construction introduction
Compiler Construction introductionCompiler Construction introduction
Compiler Construction introductionRana Ehtisham Ul Haq
 
C:\Documents And Settings\Fredlin\Desktop\Ic Design\Synthesis200301
C:\Documents And Settings\Fredlin\Desktop\Ic Design\Synthesis200301C:\Documents And Settings\Fredlin\Desktop\Ic Design\Synthesis200301
C:\Documents And Settings\Fredlin\Desktop\Ic Design\Synthesis200301guest77988fe
 
Advance data structure & algorithm
Advance data structure & algorithmAdvance data structure & algorithm
Advance data structure & algorithmK Hari Shankar
 
Computer Networks Foundation - Study Notes
Computer Networks Foundation - Study NotesComputer Networks Foundation - Study Notes
Computer Networks Foundation - Study NotesMarius FAILLOT DEVARRE
 
Ionuț G. Stan - Let’s write a type checker at I T.A.K.E. Unconference 2015
Ionuț G. Stan - Let’s write a type checker at I T.A.K.E. Unconference 2015Ionuț G. Stan - Let’s write a type checker at I T.A.K.E. Unconference 2015
Ionuț G. Stan - Let’s write a type checker at I T.A.K.E. Unconference 2015Mozaic Works
 
Cryptography & Network Security By, Er. Swapnil Kaware
Cryptography & Network Security By, Er. Swapnil KawareCryptography & Network Security By, Er. Swapnil Kaware
Cryptography & Network Security By, Er. Swapnil KawareProf. Swapnil V. Kaware
 
Compiler Construction
Compiler ConstructionCompiler Construction
Compiler ConstructionSarmad Ali
 
MMS2401 - Multimedia system and Communication Notes
MMS2401 - Multimedia system and Communication NotesMMS2401 - Multimedia system and Communication Notes
MMS2401 - Multimedia system and Communication NotesPratik Pradhan
 
Cryptography for software engineers
Cryptography for software engineersCryptography for software engineers
Cryptography for software engineersJas Chhabra
 
Chapter Eight(3)
Chapter Eight(3)Chapter Eight(3)
Chapter Eight(3)bolovv
 
Compiler Construction Course - Introduction
Compiler Construction Course - IntroductionCompiler Construction Course - Introduction
Compiler Construction Course - IntroductionMuhammad Sanaullah
 
Software engineering lecture notes
Software engineering   lecture notesSoftware engineering   lecture notes
Software engineering lecture notesAmmar Shafiq
 
Logic synthesis with synopsys design compiler
Logic synthesis with synopsys design compilerLogic synthesis with synopsys design compiler
Logic synthesis with synopsys design compilernaeemtayyab
 
Computer Networks Lecture Notes
Computer Networks Lecture NotesComputer Networks Lecture Notes
Computer Networks Lecture NotesFellowBuddy.com
 
Data Type Conversion in C++
Data Type Conversion in C++Data Type Conversion in C++
Data Type Conversion in C++Danial Mirza
 
Introduction to computer graphics
Introduction to computer graphics Introduction to computer graphics
Introduction to computer graphics Priyodarshini Dhar
 

Viewers also liked (20)

Compiler Construction
Compiler ConstructionCompiler Construction
Compiler Construction
 
Compiler Construction introduction
Compiler Construction introductionCompiler Construction introduction
Compiler Construction introduction
 
Lexical analyzer
Lexical analyzerLexical analyzer
Lexical analyzer
 
C:\Documents And Settings\Fredlin\Desktop\Ic Design\Synthesis200301
C:\Documents And Settings\Fredlin\Desktop\Ic Design\Synthesis200301C:\Documents And Settings\Fredlin\Desktop\Ic Design\Synthesis200301
C:\Documents And Settings\Fredlin\Desktop\Ic Design\Synthesis200301
 
X Windows
X WindowsX Windows
X Windows
 
Advance data structure & algorithm
Advance data structure & algorithmAdvance data structure & algorithm
Advance data structure & algorithm
 
Computer Networks Foundation - Study Notes
Computer Networks Foundation - Study NotesComputer Networks Foundation - Study Notes
Computer Networks Foundation - Study Notes
 
Ionuț G. Stan - Let’s write a type checker at I T.A.K.E. Unconference 2015
Ionuț G. Stan - Let’s write a type checker at I T.A.K.E. Unconference 2015Ionuț G. Stan - Let’s write a type checker at I T.A.K.E. Unconference 2015
Ionuț G. Stan - Let’s write a type checker at I T.A.K.E. Unconference 2015
 
Ch6
Ch6Ch6
Ch6
 
Cryptography & Network Security By, Er. Swapnil Kaware
Cryptography & Network Security By, Er. Swapnil KawareCryptography & Network Security By, Er. Swapnil Kaware
Cryptography & Network Security By, Er. Swapnil Kaware
 
Compiler Construction
Compiler ConstructionCompiler Construction
Compiler Construction
 
MMS2401 - Multimedia system and Communication Notes
MMS2401 - Multimedia system and Communication NotesMMS2401 - Multimedia system and Communication Notes
MMS2401 - Multimedia system and Communication Notes
 
Cryptography for software engineers
Cryptography for software engineersCryptography for software engineers
Cryptography for software engineers
 
Chapter Eight(3)
Chapter Eight(3)Chapter Eight(3)
Chapter Eight(3)
 
Compiler Construction Course - Introduction
Compiler Construction Course - IntroductionCompiler Construction Course - Introduction
Compiler Construction Course - Introduction
 
Software engineering lecture notes
Software engineering   lecture notesSoftware engineering   lecture notes
Software engineering lecture notes
 
Logic synthesis with synopsys design compiler
Logic synthesis with synopsys design compilerLogic synthesis with synopsys design compiler
Logic synthesis with synopsys design compiler
 
Computer Networks Lecture Notes
Computer Networks Lecture NotesComputer Networks Lecture Notes
Computer Networks Lecture Notes
 
Data Type Conversion in C++
Data Type Conversion in C++Data Type Conversion in C++
Data Type Conversion in C++
 
Introduction to computer graphics
Introduction to computer graphics Introduction to computer graphics
Introduction to computer graphics
 

Similar to Compiler construction

Lexical analysis
Lexical analysisLexical analysis
Lexical analysiswaqar ahmed
 
mt_cat_presentations CAT TRANSLATION PPT
mt_cat_presentations CAT TRANSLATION PPTmt_cat_presentations CAT TRANSLATION PPT
mt_cat_presentations CAT TRANSLATION PPTRamdan43
 
Compiler_Project_Srikanth_Vanama
Compiler_Project_Srikanth_VanamaCompiler_Project_Srikanth_Vanama
Compiler_Project_Srikanth_VanamaSrikanth Vanama
 
match the following attributes to the parts of a compilerstrips ou.pdf
match the following attributes to the parts of a compilerstrips ou.pdfmatch the following attributes to the parts of a compilerstrips ou.pdf
match the following attributes to the parts of a compilerstrips ou.pdfarpitaeron555
 
Compier Design_Unit I.ppt
Compier Design_Unit I.pptCompier Design_Unit I.ppt
Compier Design_Unit I.pptsivaganesh293
 
Compier Design_Unit I.ppt
Compier Design_Unit I.pptCompier Design_Unit I.ppt
Compier Design_Unit I.pptsivaganesh293
 
role of lexical anaysis
role of lexical anaysisrole of lexical anaysis
role of lexical anaysisSudhaa Ravi
 
Declare Your Language: Syntax Definition
Declare Your Language: Syntax DefinitionDeclare Your Language: Syntax Definition
Declare Your Language: Syntax DefinitionEelco Visser
 
Introduction to Compilers
Introduction to CompilersIntroduction to Compilers
Introduction to Compilersvijaya603274
 
lec00-Introduction.pdf
lec00-Introduction.pdflec00-Introduction.pdf
lec00-Introduction.pdfwigewej294
 
Compier Design_Unit I_SRM.ppt
Compier Design_Unit I_SRM.pptCompier Design_Unit I_SRM.ppt
Compier Design_Unit I_SRM.pptApoorv Diwan
 

Similar to Compiler construction (20)

Lexical analysis
Lexical analysisLexical analysis
Lexical analysis
 
Plc part 2
Plc  part 2Plc  part 2
Plc part 2
 
mt_cat_presentations CAT TRANSLATION PPT
mt_cat_presentations CAT TRANSLATION PPTmt_cat_presentations CAT TRANSLATION PPT
mt_cat_presentations CAT TRANSLATION PPT
 
Compiler_Project_Srikanth_Vanama
Compiler_Project_Srikanth_VanamaCompiler_Project_Srikanth_Vanama
Compiler_Project_Srikanth_Vanama
 
match the following attributes to the parts of a compilerstrips ou.pdf
match the following attributes to the parts of a compilerstrips ou.pdfmatch the following attributes to the parts of a compilerstrips ou.pdf
match the following attributes to the parts of a compilerstrips ou.pdf
 
Compier Design_Unit I.ppt
Compier Design_Unit I.pptCompier Design_Unit I.ppt
Compier Design_Unit I.ppt
 
Compier Design_Unit I.ppt
Compier Design_Unit I.pptCompier Design_Unit I.ppt
Compier Design_Unit I.ppt
 
role of lexical anaysis
role of lexical anaysisrole of lexical anaysis
role of lexical anaysis
 
Declare Your Language: Syntax Definition
Declare Your Language: Syntax DefinitionDeclare Your Language: Syntax Definition
Declare Your Language: Syntax Definition
 
Introduction to Compilers
Introduction to CompilersIntroduction to Compilers
Introduction to Compilers
 
Language processors
Language processorsLanguage processors
Language processors
 
Compiler Design
Compiler DesignCompiler Design
Compiler Design
 
Parsing
ParsingParsing
Parsing
 
Ss ui lecture 2
Ss ui lecture 2Ss ui lecture 2
Ss ui lecture 2
 
lec00-Introduction.pdf
lec00-Introduction.pdflec00-Introduction.pdf
lec00-Introduction.pdf
 
Compier Design_Unit I_SRM.ppt
Compier Design_Unit I_SRM.pptCompier Design_Unit I_SRM.ppt
Compier Design_Unit I_SRM.ppt
 
Pcd question bank
Pcd question bank Pcd question bank
Pcd question bank
 
Chapter#01 cc
Chapter#01 ccChapter#01 cc
Chapter#01 cc
 
Presentation1
Presentation1Presentation1
Presentation1
 
Presentation1
Presentation1Presentation1
Presentation1
 

More from Muhammed Afsal Villan

Software engineering : Layered Architecture
Software engineering : Layered ArchitectureSoftware engineering : Layered Architecture
Software engineering : Layered ArchitectureMuhammed Afsal Villan
 
Bluetooth - Comprehensive Presentation
Bluetooth - Comprehensive PresentationBluetooth - Comprehensive Presentation
Bluetooth - Comprehensive PresentationMuhammed Afsal Villan
 
3D Graphics : Computer Graphics Fundamentals
3D Graphics : Computer Graphics Fundamentals3D Graphics : Computer Graphics Fundamentals
3D Graphics : Computer Graphics FundamentalsMuhammed Afsal Villan
 
Barcodes - Types, Working and Hardware
Barcodes - Types, Working and HardwareBarcodes - Types, Working and Hardware
Barcodes - Types, Working and HardwareMuhammed Afsal Villan
 
Direct memory access (dma) with 8257 DMA Controller
Direct memory access (dma) with 8257 DMA ControllerDirect memory access (dma) with 8257 DMA Controller
Direct memory access (dma) with 8257 DMA ControllerMuhammed Afsal Villan
 

More from Muhammed Afsal Villan (9)

Software engineering : Layered Architecture
Software engineering : Layered ArchitectureSoftware engineering : Layered Architecture
Software engineering : Layered Architecture
 
Software development process models
Software development process modelsSoftware development process models
Software development process models
 
Bluetooth - Comprehensive Presentation
Bluetooth - Comprehensive PresentationBluetooth - Comprehensive Presentation
Bluetooth - Comprehensive Presentation
 
3D Graphics : Computer Graphics Fundamentals
3D Graphics : Computer Graphics Fundamentals3D Graphics : Computer Graphics Fundamentals
3D Graphics : Computer Graphics Fundamentals
 
Properties of Fourier transform
Properties of Fourier transformProperties of Fourier transform
Properties of Fourier transform
 
Barcodes - Types, Working and Hardware
Barcodes - Types, Working and HardwareBarcodes - Types, Working and Hardware
Barcodes - Types, Working and Hardware
 
8255 Programmable parallel I/O
8255 Programmable parallel I/O 8255 Programmable parallel I/O
8255 Programmable parallel I/O
 
Direct memory access (dma) with 8257 DMA Controller
Direct memory access (dma) with 8257 DMA ControllerDirect memory access (dma) with 8257 DMA Controller
Direct memory access (dma) with 8257 DMA Controller
 
Programmable Timer 8253/8254
Programmable Timer 8253/8254Programmable Timer 8253/8254
Programmable Timer 8253/8254
 

Recently uploaded

A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxComplianceQuest1
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerThousandEyes
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...ICS
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comFatema Valibhai
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsJhone kinadey
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdfWave PLM
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsArshad QA
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxbodapatigopi8531
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️Delhi Call girls
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...harshavardhanraghave
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...Health
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AIABDERRAOUF MEHENNI
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providermohitmore19
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfkalichargn70th171
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...kellynguyen01
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfkalichargn70th171
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionSolGuruz
 

Recently uploaded (20)

A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docx
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial Goals
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS LiveVip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptx
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with Precision
 

Compiler construction

  • 1. Jeena Thomas, Asst Professor, CSE, SJCET Palai 1
  • 2. » Phases of a compiler » Analysis and synthesis phases Jeena Thomas, Asst Professor, CSE, SJCET Palai 2
  • 3. » A compiler is a kind of translator. TRANSLATORSoftware that accepts text in certain language (SOURCE LANGUAGE) Text in another language ,preserving the meaning of text (TARGET/OBJECT LANGUAGE) Jeena Thomas, Asst Professor, CSE, SJCET Palai 3
  • 4. » A translator, is a generalized form of compiler. » When the object language is a low level language, such a translator is called a compiler. » This conversion process is essential for the hardware to interpret and perform the semantics of the input program. » As an important part of this translation process, the compiler reports to its user the presence of errors in source program. Jeena Thomas, Asst Professor, CSE, SJCET Palai 4
  • 5. Jeena Thomas, Asst Professor, CSE, SJCET Palai 5
  • 6. » Compiler is a program written in source language and translates it into an equivalent target language. Jeena Thomas, Asst Professor, CSE, SJCET Palai 6
  • 7. » Source code » a=(b+c)*(b+c)*2 Target code MOV b,R2 ADD R2,c MUL R2,R2 MUL R2, #2.0 MOV R2,a 7 Jeena Thomas, Asst Professor, CSE, SJCET Palai
  • 8. » FORTRAN compilers of the late 1950s » 18 person-years to build 8 Jeena Thomas, Asst Professor, CSE, SJCET Palai
  • 9. » Writing a compiler gives a student experience with large- scale applications development. Your compiler program may be the largest program you write as a student. Experience working with really big data structures and complex interactions between algorithms will help you out on your next big programming project. » Compiler writing is one of the shining triumphs of CS theory. It demonstrates the value of theory over the impulse to just "hack up" a solution. » Compiler writing is a basic element of programming language research. Many language researchers write compilers for the languages they design. » Many applications have similar properties to one or more phases of a compiler, and compiler expertise and tools can help an application programmer working on other projects besides compiler Jeena Thomas, Asst Professor, CSE, SJCET Palai 9
  • 10. » Throughout the 1950’s, compilers were considered difficult programs to write. » The first Fortan compiler took 18 staff-years o implement. » Good implementation languages, programming environments, and software tool has been developed as the systematic techniques for handling many of important tasks that occur during compilation. » With these advances, a substantial compiler can be implemented even as a student project in a one- semester compiler-design course. Jeena Thomas, Asst Professor, CSE, SJCET Palai 10
  • 11. » is more broadly applicable and has been employed in rather unexpected areas. » Text-formatting languages, preprocessor packages » Silicon compiler for the creation of VLSI circuits » Command languages of OS » Query languages of Database systems 11 Jeena Thomas, Asst Professor, CSE, SJCET Palai
  • 12. » Hierarchy of operations to be maintained -to determine the correct order of evaluation of the expressions.  Maintaining data type integrity -each part of complex expression can be made of different types.  Compiler as prior knowledge about the nature of user defined data types. - struct, enum, union,  Appropriate storage mappings for data structures - allocation of memory for data Jeena Thomas, Asst Professor, CSE, SJCET Palai 12
  • 13. » The compiler must resolve the occurrence of each variable name in a program to determine the name space to which a referenced variable belongs to.(Symbol table) » Compiler should have facilities to handle different control structures like ‘if-then-else’, ‘for’, ‘while’ etc. The compiler should have the facilities to increment the loop variable and terminate the loop. 13 Jeena Thomas, Asst Professor, CSE, SJCET Palai
  • 14. » Process of compilation is highly complex, it is split into a series of subprocesses called phases. » A phase is a logically cohesive operation that takes as input one representation of source program and produces as output another representation. » Activities of compilation split into two parts 1) Analysis part 2) Synthesis part 14 Jeena Thomas, Asst Professor, CSE, SJCET Palai
  • 15. 15 Jeena Thomas, Asst Professor, CSE, SJCET Palai
  • 16. » Analysis of source program » is done by the front end of compiler » It determines meaning of source string. » Synthesis of target program » Is done by the back end of the compiler. » An equivalent target string is constructed from the output given by the front end of compiler. 16 Jeena Thomas, Asst Professor, CSE, SJCET Palai
  • 17. » In compiling, analysis has three phases: » Linear analysis: stream of characters read from left-to-right and grouped into tokens; known as lexical analysis or scanning » Hierarchical analysis: tokens grouped hierarchically with collective meaning; known as parsing or syntax analysis » Semantic analysis: check if the program components fit together meaningfully 17 Jeena Thomas, Asst Professor, CSE, SJCET Palai
  • 18. » Optimization of code » Allocation of memory » Generation of code 18 Jeena Thomas, Asst Professor, CSE, SJCET Palai
  • 19. Jeena Thomas, Asst Professor, CSE, SJCET Palai 19
  • 20. 20 Jeena Thomas, Asst Professor, CSE, SJCET Palai
  • 21. » Performs the linear analysis on the source program. » It reads a stream of characters making up the source program from left to right and groups them into tokens. » A token is defined as a sequence of characters that have a collective meaning. » For each token identified, this phase also determines the category of the token as identifier, constant or reserved words and its attribute that identifies the symbol’ position in the symbol table 21 Jeena Thomas, Asst Professor, CSE, SJCET Palai
  • 22. 22 Jeena Thomas, Asst Professor, CSE, SJCET Palai
  • 23. » Identifiers are names of variables, constants, functions, data types, etc. » Store information associated with identifiers » Information associated with different types of identifiers can be different » Information associated with variables are name, type, address, size (for array), etc. » Information associated with functions are name , type of return value, parameters, address, etc. 23 Jeena Thomas, Asst Professor, CSE, SJCET Palai
  • 24. » Consider the following statement » a=(b+c)*(b+c)*2--------------------------------(1) 24 Jeena Thomas, Asst Professor, CSE, SJCET Palai
  • 25. Symbol Category Attribute a Identifier #1 = operator Assignment(1) b Identifier #2 + operator Arithmetic(1) c Identifier #3 * operator Arithmetic(2) ( operator Open parenthesis(1) ) operator Closed parenthesis(1) 2 Constant #4 25 Jeena Thomas, Asst Professor, CSE, SJCET Palai
  • 26. » This phase performs hierarchical analysis on the source program. » Here, the tokens are grouped into hierarchically nested collections with collective meaning called expressions or statements. » It determines structure of source language. » Represents the grammar / syntax of the language. » These grammatical phrases are represented in the form of parse tree. 26 Jeena Thomas, Asst Professor, CSE, SJCET Palai
  • 27. » Describes the syntactic structure of input » The terminal nodes represent the tokens and interior nodes represent the expressions. 27 Jeena Thomas, Asst Professor, CSE, SJCET Palai
  • 28. » Syntactic structures also represented using syntax trees. » A syntax tree is a compressed representation of the parse tree, where the operators appear as interior nodes and operands for this operator as their children 28 Jeena Thomas, Asst Professor, CSE, SJCET Palai
  • 29. » Syntax tree is a compressed representation of a parse tree. » The interior node in a syntax tree represent an operator, whereas the interior nodes in a parse tree represent an expression. » The leaf node of a syntax tree represent the operand, whereas leaf node in a parse tree represent the tokens. 29 Jeena Thomas, Asst Professor, CSE, SJCET Palai
  • 30. » Goal- is to determine the meaning of a source string. » It checks the source program for semantic errors and gathers the type of information that can be used in subsequent phases of compilation. » Type checking for operations also performed during this phase. » Output- Annotated tree 30 Jeena Thomas, Asst Professor, CSE, SJCET Palai
  • 31. » It is a part of the synthesis process of the compiler. » The intermediate code is the representation for an abstract machine. » Using the intermediate code, optimization and code generation can be performed. 31 Jeena Thomas, Asst Professor, CSE, SJCET Palai
  • 32. » It should be easily generated from semantic representation of the source program. » It should be easy to translate the intermediate code to target language. » It should be capable of holding the values computed during translation. » It should maintain precedence ordering of the source language. » It should be capable of holding the correct number of operands of the instruction. 32 Jeena Thomas, Asst Professor, CSE, SJCET Palai
  • 33. » T1=intoreal(2) » T2=b+c » T3=b+c » T4=T2*T3 » T5=T4*T1 » a=T5 33 Jeena Thomas, Asst Professor, CSE, SJCET Palai
  • 34. » The main aim of this phase is to improve on the intermediate code to generate a code that runs faster and/or occupies less space. » It is used to establish trade off between compilation speed and execution speed. 34 Jeena Thomas, Asst Professor, CSE, SJCET Palai
  • 35. » T1=inttoreal(2) » T2=b+c » T3=T2*T2 » T4=T3*T1 » a=T4 35 Jeena Thomas, Asst Professor, CSE, SJCET Palai
  • 36. » The main aim of this phase is to allocate storage and generate a relocatable machine/ assembly code. » Memory locations and registers are allocated for variables. » The instructions in intermediate code format are converted into machine instructions. 36 Jeena Thomas, Asst Professor, CSE, SJCET Palai
  • 37. » MOV R2, b » ADD R2,c » MUL R2,R2 » MUL R2, #2.0 » MOV R2, a 37 Jeena Thomas, Asst Professor, CSE, SJCET Palai
  • 38. » The compiler also attempts to improve the target code generated by the code generator by choosing proper addressing modes to improve the performance, replacing slow instructions by fast ones and eliminating redundant instructions. » MUL R2, #2.0-------------------SHL(Shift Left Instruction) 38 Jeena Thomas, Asst Professor, CSE, SJCET Palai
  • 39. » MOV b, R2 » ADD R2,c » MUL R2,R2 » SHL R2 » MOV R2, a 39 Jeena Thomas, Asst Professor, CSE, SJCET Palai
  • 40. » 1.)Symbol Table Management » 2.) Literal Table Management » 3.) Error Detection and Reporting 40 Jeena Thomas, Asst Professor, CSE, SJCET Palai
  • 41. » A symbol table is a data structure that contains a record for each identifier with fields for the attributes of the identifier. » This data structure has facilities to manipulate(add/delete) the elements in it. » The type information about the identifier is detected during lexical analysis phase and is entered into the symbol table. » This information is used during the intermediate code generation and code generation phases of compiler to verify type information. 41 Jeena Thomas, Asst Professor, CSE, SJCET Palai
  • 42. 42 Jeena Thomas, Asst Professor, CSE, SJCET Palai Address Symbol Attribute Memory Location 1 A id,real 1000 2 B id,real 1100 3 C id,real 1110
  • 43. » literal table maintains the details of constants and strings used in the program. » It reduces the size of a program in memory by allowing reuse of constants and strings. » It is also needed by the code generator to construct symbolic addresses for literals. 43 Jeena Thomas, Asst Professor, CSE, SJCET Palai
  • 44. Address Literal Attribute Memory Location 4 2 const,int 1200 44 Jeena Thomas, Asst Professor, CSE, SJCET Palai
  • 45. » Each phase encounters errors. » After detecting the errors, this phase must deal with the errors to continue with the process of compilation. 45 Jeena Thomas, Asst Professor, CSE, SJCET Palai
  • 46. » 1. Lexical analyzer: Misspelled tokens » 2.Syntax analyzer: syntax errors like missing parenthesis » 3.Intermediate code generator: Incompatible operands for an operator » 4. Code Optimizer: Unreachable statements » 5. Code Generator :Memory restrictions to store a variable. For example, when the value of an integer variable exceeds its size. » Symbol tables: Multiply declared identifiers 46 Jeena Thomas, Asst Professor, CSE, SJCET Palai
  • 47. » Show the output of all the phases of he compiler for the following line o code » A[index]=4+2+index 47 Jeena Thomas, Asst Professor, CSE, SJCET Palai
  • 48. 48 Jeena Thomas, Asst Professor, CSE, SJCET Palai
  • 49. 49 Jeena Thomas, Asst Professor, CSE, SJCET Palai
  • 50. » Scanner generators » Parser generators » Syntax-directed translation engines » Automatic code generators » Data-flow engines 50 Jeena Thomas, Asst Professor, CSE, SJCET Palai
  • 51. » Scanner generators: » generate lexical analyzers automatically from the language specifications written using regular expressions. » It generates a finite automaton to recognize the regular expression. » Example-lex 51 Jeena Thomas, Asst Professor, CSE, SJCET Palai
  • 52. » parser generators » They produce syntax analyzers from Context Free Grammar(CFG). » As syntax analysis phase is highly complex and consumes manual and compilation time, these parser generators are highly useful. » Example-yacc 52 Jeena Thomas, Asst Professor, CSE, SJCET Palai
  • 53. » Syntax-directed translation engines » These engines have routines to traverse the parse tree and produce intermediate code. » The basic idea is that one or more translations are associated with each node of parse tree. 53 Jeena Thomas, Asst Professor, CSE, SJCET Palai
  • 54. » Automatic code generators » These tools convert the intermediate language into machine language for the target machine using a collection of rules. » Template matching process is used. » An intermediate language statement is replaced by its equivalent machine language statement 54 Jeena Thomas, Asst Professor, CSE, SJCET Palai
  • 55. » Data-flow engines » It is used in code optimization. » These tools perform good code optimization using “data-flow analysis” which gathers information that flows from one part of the program to another. 55 Jeena Thomas, Asst Professor, CSE, SJCET Palai