尊敬的 微信汇率:1円 ≈ 0.046166 元 支付宝汇率:1円 ≈ 0.046257元 [退出登录]
SlideShare a Scribd company logo
SHREE SWAMI ATMANAND SARASWATI INSTITUTE
OF TECHNOLOGY
Compiler Design(2170701)
PREPARED BY: (Group:1)
Bhumi Aghera(130760107001)
Monika Dudhat(130760107007)
Radhika Talaviya(130760107029)
Rajvi Vaghasiya(130760107031)
The Phases of a Compiler
GUIDED BY:
Prof. Akhilesh Ladha
Language Processing System
• We have learnt that any computer system is made of hardware and software.
• The hardware understands a language, which humans cannot understand. So we write
programs in high-level language, which is easier for us to understand and remember.
• These programs are then fed into a series of tools and OS components to get the desired
code that can be used by the machine.
• This is known as Language Processing System.
Language Processing System
Phases of Compiler
• There are mainly two parts of compilation process.
1. Analysis phase
2. Synthesis phase
1. Analysis phase: The main objective of the Analysis phase is to break the source code into
parts and then arranges these pieces into a meaningful structure.
• The analysis phase also collect information about source program and stores it in a data
structure called symbol table.
• The analysis phase is often called the front end of compiler.
• Analysis phase contains:
I. Lexical analysis
II. Syntax analysis
III. Semantic analysis
2. Synthesis phase: Synthesis phase is concerned with generation of target language statement
which has the same meaning as the source statement.
• The synthesis phase is often called the back end of compiler.
• Synthesis phase contains:
I. Intermediate code generation
II. Code optimization
III. Code generation
Phases of Compiler
Phases of Compiler
Lexical Analysis
• The first phase of a compiler is called lexical analysis or scanning.
• The lexical analyzer takes the modified source code from language preprocessors that are
written in the form of sentences.
• The lexical analyzer reads the stream of characters making up the source program and groups
the characters into meaningful sequences called lexemes.
• Lexical analyzer represents these lexemes in the form of tokens as:
<token-name, attribute-value>
where, token-name: an abstract symbol is used during syntax analysis.
attribute-value: points to an entry in the symbol table for this token.
Lexical analysisInput string Tokens or lexemes
Tokens, Patterns And Lexemes
Token: Token is a sequence of characters that can be treated as a single logical entity.
Typical tokens are,
Identifiers
keywords
operators
special symbols
constants
Pattern: A set of strings in the input for which the same token is produced as output. This
set of strings is described by a rule called a pattern associated with the token.
Lexeme: A lexeme is a sequence of characters in the source program that is matched by
the pattern for a token.
Tokenization
• Process of forming tokens from input stream is called tokenization.
div = 6/2;
Lexeme Token
div Identifier
= Assignment symbol
6 Number
/ Division operator
2 Number
; End of statement
Type Example
Comment /* ignored */
Preprocessor directive #include<stdio.h>
#define NUMS 5
Macro NUMS
whitespace t n b
Type Example
ID foo n_14 last
NUM 73 00 517 082
REAL 66.1 .5 10. 1e67 5.5e-10
COMMA ,
NOTEQ !=
LPAREN (
RPAREN )
Examples of tokens
Example of non-tokens
Tasks – lexical analyzer
• Separation of the input source code into tokens.
• Remove the unnecessary white spaces from the source code.
• Removing the comments from the source text.
• Keeping track of line numbers while scanning the new line characters. These line numbers
are used by the error handler to print the error messages.
• Preprocessing of macros.
Syntax Analysis
• The second phase of the compiler is called the syntax analysis or parsing.
• It takes the token produced by lexical analysis as input and generates a parse tree (or syntax
tree).
• The parser uses the first components of the tokens produced by the lexical analyzer to create
a tree-like intermediate representation that depicts the grammatical structure of the token
stream.
• A typical representation is a syntax tree in which each interior node represents an operation
and the children of the node represent the arguments of the operation.
• In this phase, token arrangements are checked against the source code grammar, i.e. the
parser checks if the expression made by the tokens is syntactically correct.
Parse tree
• It shows how the start symbol of a grammar derives a string in the language
• root is labeled by the start symbol
• leaf nodes are labeled by tokens
• Each internal node is labeled by a non terminal
• if A is a non-terminal labeling an internal node and x1, x2, …xn are labels of children of that
node then A  x1 x2 … xn is a production
• For example,
Parse tree for 9-5+2
list
list
list
digit
digit
+
-
digit
9
5
2
Semantic Analysis
• The semantic analyzer uses the syntax tree and the information in the symbol table to check
the source program for semantic consistency with the language definition.
• It also gathers type information and saves it in either the syntax tree or the symbol table, for
subsequent use during intermediate-code generation.
• An important part of semantic analysis is type checking, where the compiler checks that each
operator has matching operands.
• For example, many programming language definitions require an array index to be an integer;
the compiler must report an error if a floating-point number is used to index an array.
• The language specification may permit some type conversions called coercions.
Semantic Analysis
• For example, a binary arithmetic operator may be applied to either a pair of integers or to a
pair of floating point numbers. If the operator is applied to a floating-point number and an
integer, the compiler may convert or coerce the integer to a floating-point number. As shown
in figure given below:
position = initial + rate * 60
=
<id,1>
+
<id,2> *
<id,3> 60
=
<id,1> +
<id,2> *
<id,3>
digit
60
Syntax Tree Semantic Tree
Intermediate Code Generation
• In the process of translating a source program into target code, a compiler may construct one
or more intermediate representation; they are commonly used during syntax and semantic
analysis.
• After syntax and semantic analysis of the source program, many compilers generate an
explicit low-level or machine-like intermediate representation.
• This intermediate representation should have two important properties:
1. It should be easy to produce.
2. It should be easy to translate into the target machine.
Intermediate Code Generation
• The considered intermediate form called three-address code, which consists of a sequence of
assembly-like instructions with three operands per instruction.
• Each operand can act like a register.
• Three address code sequence of intermediate code generator is as follows:
position = initial + rate * 60
Three-address code:
t1 = inttofloat(60)
t2 = id3 * t1
t3 = id2 + t2
id1 = t3
• Each three-address assignment instruction has at most one operator on the right side. These
instructions fix the order in which operations to be done.
Code Optimization
• The next phase does code optimization of the intermediate code.
• Optimization can be assumed as something that removes unnecessary code lines, and
arranges the sequence of statements in order to speed up the program execution without
wasting resources (CPU, memory) and deliver high speed
• In optimization, high-level general programming constructs are replaced by very efficient
low-level programming codes.
• A code optimizing process must follow the three rules given below:
• The output code must not, in any way, change the meaning of the program.
• Optimization should increase the speed of the program and if possible, the program
should demand less number of resources.
• Optimization should itself be fast and should not delay the overall compiling process.
Code Optimization
• Efforts for an optimized code can be made at various levels of compiling the process.
• At the beginning, users can change/rearrange the code or use better algorithms to write
the code.
• After generating intermediate code, the compiler can modify the intermediate code by
address calculations and improving loops.
• While producing the target machine code, the compiler can make use of memory
hierarchy and CPU registers.
• Optimization can be categorized broadly into two types :
1) Machine independent
2) Machine dependent.
Machine-independent Optimization
• In this optimization, the compiler takes in the intermediate code and transforms a part of the
code that does not involve any CPU registers and/or absolute memory locations.
• For example:
do{
i=10;
v=v+i;
}while(v<10);
• This code involves repeated assignment of the identifier i, which if we put this way:
i=10;
do{
v=v+i;
}while(v<10);
Machine-dependent Optimization
• Machine-dependent optimization is done after the target code has been generated and when
the code is transformed according to the target machine architecture.
• It involves CPU registers and may have absolute memory references rather than relative
references. Machine-dependent optimizers put efforts to take maximum advantage of
memory hierarchy.
• Code generation can be considered as the final phase of compilation.
• In this phase, the code generator takes the optimized representation of the intermediate code
and maps it to the target machine language.
• The code generator translates the intermediate code into a sequence of (generally) re-
locatable machine code. Sequence of instructions of machine code performs the task as the
intermediate code would do.
• Through post code generation, optimization process can be applied on the code, but that can
be seen as a part of code generation phase itself.
• The code generated by the compiler is an object code of some lower-level programming
language, for example, assembly language.
• The source code written in a higher-level language is transformed into a lower-level language
that results in a lower-level object code, which should have the following minimum
properties:
• It should carry the exact meaning of the source code.
• It should be efficient in terms of CPU usage and memory management.
Code Generation
The Phases of a Compiler

More Related Content

What's hot

Assembler
AssemblerAssembler
Assembler
manpreetgrewal
 
Three address code In Compiler Design
Three address code In Compiler DesignThree address code In Compiler Design
Three address code In Compiler Design
Shine Raj
 
Role-of-lexical-analysis
Role-of-lexical-analysisRole-of-lexical-analysis
Role-of-lexical-analysis
Dattatray Gandhmal
 
Phases of compiler
Phases of compilerPhases of compiler
Phases of compiler
PANKAJKUMAR2519
 
Three Address code
Three Address code Three Address code
Three Address code
Pooja Dixit
 
Compiler Construction
Compiler ConstructionCompiler Construction
Recognition-of-tokens
Recognition-of-tokensRecognition-of-tokens
Recognition-of-tokens
Dattatray Gandhmal
 
Toy compiler
Toy compilerToy compiler
Toy compiler
home
 
Phases of compiler
Phases of compilerPhases of compiler
Phases of compiler
Karan Deopura
 
Lexical analysis - Compiler Design
Lexical analysis - Compiler DesignLexical analysis - Compiler Design
Lexical analysis - Compiler Design
Muhammed Afsal Villan
 
Passes of compilers
Passes of compilersPasses of compilers
Passes of compilers
Vairavel C
 
Compiler construction tools
Compiler construction toolsCompiler construction tools
Compiler construction tools
Akhil Kaushik
 
Compiler Design Unit 1
Compiler Design Unit 1Compiler Design Unit 1
Compiler Design Unit 1
Jena Catherine Bel D
 
Syntax Analysis in Compiler Design
Syntax Analysis in Compiler Design Syntax Analysis in Compiler Design
Syntax Analysis in Compiler Design
MAHASREEM
 
Ch 4 linker loader
Ch 4 linker loaderCh 4 linker loader
Ch 4 linker loader
Malek Sumaiya
 
Lecture 12 intermediate code generation
Lecture 12 intermediate code generationLecture 12 intermediate code generation
Lecture 12 intermediate code generation
Iffat Anjum
 
Phases of Compiler
Phases of CompilerPhases of Compiler
Phases of Compiler
Tanzeela_Hussain
 
1.Role lexical Analyzer
1.Role lexical Analyzer1.Role lexical Analyzer
1.Role lexical Analyzer
Radhakrishnan Chinnusamy
 
Introduction to Compiler design
Introduction to Compiler design Introduction to Compiler design
Introduction to Compiler design
Dr. C.V. Suresh Babu
 
Compilers
CompilersCompilers
Compilers
Bense Tony
 

What's hot (20)

Assembler
AssemblerAssembler
Assembler
 
Three address code In Compiler Design
Three address code In Compiler DesignThree address code In Compiler Design
Three address code In Compiler Design
 
Role-of-lexical-analysis
Role-of-lexical-analysisRole-of-lexical-analysis
Role-of-lexical-analysis
 
Phases of compiler
Phases of compilerPhases of compiler
Phases of compiler
 
Three Address code
Three Address code Three Address code
Three Address code
 
Compiler Construction
Compiler ConstructionCompiler Construction
Compiler Construction
 
Recognition-of-tokens
Recognition-of-tokensRecognition-of-tokens
Recognition-of-tokens
 
Toy compiler
Toy compilerToy compiler
Toy compiler
 
Phases of compiler
Phases of compilerPhases of compiler
Phases of compiler
 
Lexical analysis - Compiler Design
Lexical analysis - Compiler DesignLexical analysis - Compiler Design
Lexical analysis - Compiler Design
 
Passes of compilers
Passes of compilersPasses of compilers
Passes of compilers
 
Compiler construction tools
Compiler construction toolsCompiler construction tools
Compiler construction tools
 
Compiler Design Unit 1
Compiler Design Unit 1Compiler Design Unit 1
Compiler Design Unit 1
 
Syntax Analysis in Compiler Design
Syntax Analysis in Compiler Design Syntax Analysis in Compiler Design
Syntax Analysis in Compiler Design
 
Ch 4 linker loader
Ch 4 linker loaderCh 4 linker loader
Ch 4 linker loader
 
Lecture 12 intermediate code generation
Lecture 12 intermediate code generationLecture 12 intermediate code generation
Lecture 12 intermediate code generation
 
Phases of Compiler
Phases of CompilerPhases of Compiler
Phases of Compiler
 
1.Role lexical Analyzer
1.Role lexical Analyzer1.Role lexical Analyzer
1.Role lexical Analyzer
 
Introduction to Compiler design
Introduction to Compiler design Introduction to Compiler design
Introduction to Compiler design
 
Compilers
CompilersCompilers
Compilers
 

Similar to The Phases of a Compiler

Compiler Construction
Compiler ConstructionCompiler Construction
Compiler Construction
Sarmad Ali
 
Chapter 1.pptx
Chapter 1.pptxChapter 1.pptx
Chapter 1.pptx
NesredinTeshome1
 
what is compiler and five phases of compiler
what is compiler and five phases of compilerwhat is compiler and five phases of compiler
what is compiler and five phases of compiler
adilmehmood93
 
System software module 4 presentation file
System software module 4 presentation fileSystem software module 4 presentation file
System software module 4 presentation file
jithujithin657
 
Compiler Design
Compiler DesignCompiler Design
Compiler Design
Dr. Jaydeep Patil
 
Compier Design_Unit I.ppt
Compier Design_Unit I.pptCompier Design_Unit I.ppt
Compier Design_Unit I.ppt
sivaganesh293
 
Compier Design_Unit I.ppt
Compier Design_Unit I.pptCompier Design_Unit I.ppt
Compier Design_Unit I.ppt
sivaganesh293
 
Concept of compiler in details
Concept of compiler in detailsConcept of compiler in details
Concept of compiler in details
kazi_aihtesham
 
Compiler an overview
Compiler  an overviewCompiler  an overview
Compiler an overview
amudha arul
 
1._Introduction_.pptx
1._Introduction_.pptx1._Introduction_.pptx
1._Introduction_.pptx
Anbarasan Radhakrishnan R
 
COMPILER CONSTRUCTION KU 1.pptx
COMPILER CONSTRUCTION KU 1.pptxCOMPILER CONSTRUCTION KU 1.pptx
COMPILER CONSTRUCTION KU 1.pptx
Rossy719186
 
Pros and cons of c as a compiler language
  Pros and cons of c as a compiler language  Pros and cons of c as a compiler language
Pros and cons of c as a compiler language
Ashok Raj
 
Compiler Design Introduction
Compiler Design Introduction Compiler Design Introduction
Compiler Design Introduction
Thapar Institute
 
Introduction to compiler
Introduction to compilerIntroduction to compiler
Introduction to compiler
Abha Damani
 
Compiler Design Material
Compiler Design MaterialCompiler Design Material
Compiler Design Material
Dr. C.V. Suresh Babu
 
Introduction to Compilers
Introduction to CompilersIntroduction to Compilers
Introduction to Compilers
vijaya603274
 
Plc part 2
Plc  part 2Plc  part 2
Plc part 2
Taymoor Nazmy
 
Compiler Construction
Compiler ConstructionCompiler Construction
Compiler Construction
Ahmed Raza
 
Phases of Compiler.pptx
Phases of Compiler.pptxPhases of Compiler.pptx
Phases of Compiler.pptx
ssuser3b4934
 
Chapter1pdf__2021_11_23_10_53_20.pdf
Chapter1pdf__2021_11_23_10_53_20.pdfChapter1pdf__2021_11_23_10_53_20.pdf
Chapter1pdf__2021_11_23_10_53_20.pdf
DrIsikoIsaac
 

Similar to The Phases of a Compiler (20)

Compiler Construction
Compiler ConstructionCompiler Construction
Compiler Construction
 
Chapter 1.pptx
Chapter 1.pptxChapter 1.pptx
Chapter 1.pptx
 
what is compiler and five phases of compiler
what is compiler and five phases of compilerwhat is compiler and five phases of compiler
what is compiler and five phases of compiler
 
System software module 4 presentation file
System software module 4 presentation fileSystem software module 4 presentation file
System software module 4 presentation file
 
Compiler Design
Compiler DesignCompiler Design
Compiler Design
 
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
 
Concept of compiler in details
Concept of compiler in detailsConcept of compiler in details
Concept of compiler in details
 
Compiler an overview
Compiler  an overviewCompiler  an overview
Compiler an overview
 
1._Introduction_.pptx
1._Introduction_.pptx1._Introduction_.pptx
1._Introduction_.pptx
 
COMPILER CONSTRUCTION KU 1.pptx
COMPILER CONSTRUCTION KU 1.pptxCOMPILER CONSTRUCTION KU 1.pptx
COMPILER CONSTRUCTION KU 1.pptx
 
Pros and cons of c as a compiler language
  Pros and cons of c as a compiler language  Pros and cons of c as a compiler language
Pros and cons of c as a compiler language
 
Compiler Design Introduction
Compiler Design Introduction Compiler Design Introduction
Compiler Design Introduction
 
Introduction to compiler
Introduction to compilerIntroduction to compiler
Introduction to compiler
 
Compiler Design Material
Compiler Design MaterialCompiler Design Material
Compiler Design Material
 
Introduction to Compilers
Introduction to CompilersIntroduction to Compilers
Introduction to Compilers
 
Plc part 2
Plc  part 2Plc  part 2
Plc part 2
 
Compiler Construction
Compiler ConstructionCompiler Construction
Compiler Construction
 
Phases of Compiler.pptx
Phases of Compiler.pptxPhases of Compiler.pptx
Phases of Compiler.pptx
 
Chapter1pdf__2021_11_23_10_53_20.pdf
Chapter1pdf__2021_11_23_10_53_20.pdfChapter1pdf__2021_11_23_10_53_20.pdf
Chapter1pdf__2021_11_23_10_53_20.pdf
 

More from Radhika Talaviya

General Packet Radio Service(GPRS)
General Packet Radio Service(GPRS)General Packet Radio Service(GPRS)
General Packet Radio Service(GPRS)
Radhika Talaviya
 
screen speculo - Miracast android Project
screen speculo - Miracast android Projectscreen speculo - Miracast android Project
screen speculo - Miracast android Project
Radhika Talaviya
 
MICROPROCESSOR AND INTERFACING
MICROPROCESSOR AND INTERFACING MICROPROCESSOR AND INTERFACING
MICROPROCESSOR AND INTERFACING
Radhika Talaviya
 
Assembler - System Programming
Assembler - System ProgrammingAssembler - System Programming
Assembler - System Programming
Radhika Talaviya
 
Classes, Objects and Method - Object Oriented Programming with Java
Classes, Objects and Method - Object Oriented Programming with JavaClasses, Objects and Method - Object Oriented Programming with Java
Classes, Objects and Method - Object Oriented Programming with Java
Radhika Talaviya
 
Cyber Security - Firewall and Packet Filters
Cyber Security - Firewall and Packet Filters Cyber Security - Firewall and Packet Filters
Cyber Security - Firewall and Packet Filters
Radhika Talaviya
 
Shopping At Mall without standing in Queue for Bill Payment by Scanning Bar c...
Shopping At Mall without standing in Queue for Bill Payment by Scanning Bar c...Shopping At Mall without standing in Queue for Bill Payment by Scanning Bar c...
Shopping At Mall without standing in Queue for Bill Payment by Scanning Bar c...
Radhika Talaviya
 
Analysis and Design of Algorithms -Sorting Algorithms and analysis
Analysis and Design of Algorithms -Sorting Algorithms and analysisAnalysis and Design of Algorithms -Sorting Algorithms and analysis
Analysis and Design of Algorithms -Sorting Algorithms and analysis
Radhika Talaviya
 
Computer Organization
Computer Organization Computer Organization
Computer Organization
Radhika Talaviya
 
Stack
StackStack
Level, Role, and Skill manager
Level, Role, and Skill  managerLevel, Role, and Skill  manager
Level, Role, and Skill manager
Radhika Talaviya
 
Dbms relational model
Dbms relational modelDbms relational model
Dbms relational model
Radhika Talaviya
 
Global environmental essue
Global environmental essueGlobal environmental essue
Global environmental essue
Radhika Talaviya
 
Reflection of girls life
Reflection of girls lifeReflection of girls life
Reflection of girls life
Radhika Talaviya
 
Nanophysics
NanophysicsNanophysics
Nanophysics
Radhika Talaviya
 
I'm ok you're ok
I'm ok you're okI'm ok you're ok
I'm ok you're ok
Radhika Talaviya
 

More from Radhika Talaviya (16)

General Packet Radio Service(GPRS)
General Packet Radio Service(GPRS)General Packet Radio Service(GPRS)
General Packet Radio Service(GPRS)
 
screen speculo - Miracast android Project
screen speculo - Miracast android Projectscreen speculo - Miracast android Project
screen speculo - Miracast android Project
 
MICROPROCESSOR AND INTERFACING
MICROPROCESSOR AND INTERFACING MICROPROCESSOR AND INTERFACING
MICROPROCESSOR AND INTERFACING
 
Assembler - System Programming
Assembler - System ProgrammingAssembler - System Programming
Assembler - System Programming
 
Classes, Objects and Method - Object Oriented Programming with Java
Classes, Objects and Method - Object Oriented Programming with JavaClasses, Objects and Method - Object Oriented Programming with Java
Classes, Objects and Method - Object Oriented Programming with Java
 
Cyber Security - Firewall and Packet Filters
Cyber Security - Firewall and Packet Filters Cyber Security - Firewall and Packet Filters
Cyber Security - Firewall and Packet Filters
 
Shopping At Mall without standing in Queue for Bill Payment by Scanning Bar c...
Shopping At Mall without standing in Queue for Bill Payment by Scanning Bar c...Shopping At Mall without standing in Queue for Bill Payment by Scanning Bar c...
Shopping At Mall without standing in Queue for Bill Payment by Scanning Bar c...
 
Analysis and Design of Algorithms -Sorting Algorithms and analysis
Analysis and Design of Algorithms -Sorting Algorithms and analysisAnalysis and Design of Algorithms -Sorting Algorithms and analysis
Analysis and Design of Algorithms -Sorting Algorithms and analysis
 
Computer Organization
Computer Organization Computer Organization
Computer Organization
 
Stack
StackStack
Stack
 
Level, Role, and Skill manager
Level, Role, and Skill  managerLevel, Role, and Skill  manager
Level, Role, and Skill manager
 
Dbms relational model
Dbms relational modelDbms relational model
Dbms relational model
 
Global environmental essue
Global environmental essueGlobal environmental essue
Global environmental essue
 
Reflection of girls life
Reflection of girls lifeReflection of girls life
Reflection of girls life
 
Nanophysics
NanophysicsNanophysics
Nanophysics
 
I'm ok you're ok
I'm ok you're okI'm ok you're ok
I'm ok you're ok
 

Recently uploaded

Basic principle and types Static Relays ppt
Basic principle and  types  Static Relays pptBasic principle and  types  Static Relays ppt
Basic principle and types Static Relays ppt
Sri Ramakrishna Institute of Technology
 
Data Communication and Computer Networks Management System Project Report.pdf
Data Communication and Computer Networks Management System Project Report.pdfData Communication and Computer Networks Management System Project Report.pdf
Data Communication and Computer Networks Management System Project Report.pdf
Kamal Acharya
 
Sachpazis_Consolidation Settlement Calculation Program-The Python Code and th...
Sachpazis_Consolidation Settlement Calculation Program-The Python Code and th...Sachpazis_Consolidation Settlement Calculation Program-The Python Code and th...
Sachpazis_Consolidation Settlement Calculation Program-The Python Code and th...
Dr.Costas Sachpazis
 
Call Girls In Tiruppur 👯‍♀️ 7339748667 🔥 Free Home Delivery Within 30 Minutes
Call Girls In Tiruppur 👯‍♀️ 7339748667 🔥 Free Home Delivery Within 30 MinutesCall Girls In Tiruppur 👯‍♀️ 7339748667 🔥 Free Home Delivery Within 30 Minutes
Call Girls In Tiruppur 👯‍♀️ 7339748667 🔥 Free Home Delivery Within 30 Minutes
kamka4105
 
Call Girls In Lucknow 🔥 +91-7014168258🔥High Profile Call Girl Lucknow
Call Girls In Lucknow 🔥 +91-7014168258🔥High Profile Call Girl LucknowCall Girls In Lucknow 🔥 +91-7014168258🔥High Profile Call Girl Lucknow
Call Girls In Lucknow 🔥 +91-7014168258🔥High Profile Call Girl Lucknow
yogita singh$A17
 
Online train ticket booking system project.pdf
Online train ticket booking system project.pdfOnline train ticket booking system project.pdf
Online train ticket booking system project.pdf
Kamal Acharya
 
Call Girls Madurai 8824825030 Escort In Madurai service 24X7
Call Girls Madurai 8824825030 Escort In Madurai service 24X7Call Girls Madurai 8824825030 Escort In Madurai service 24X7
Call Girls Madurai 8824825030 Escort In Madurai service 24X7
Poonam Singh
 
Cricket management system ptoject report.pdf
Cricket management system ptoject report.pdfCricket management system ptoject report.pdf
Cricket management system ptoject report.pdf
Kamal Acharya
 
INTRODUCTION TO ARTIFICIAL INTELLIGENCE BASIC
INTRODUCTION TO ARTIFICIAL INTELLIGENCE BASICINTRODUCTION TO ARTIFICIAL INTELLIGENCE BASIC
INTRODUCTION TO ARTIFICIAL INTELLIGENCE BASIC
GOKULKANNANMMECLECTC
 
一比一原版(UO毕业证)渥太华大学毕业证如何办理
一比一原版(UO毕业证)渥太华大学毕业证如何办理一比一原版(UO毕业证)渥太华大学毕业证如何办理
一比一原版(UO毕业证)渥太华大学毕业证如何办理
gapboxn
 
Update 40 models( Solar Cell ) in SPICE PARK(JUL2024)
Update 40 models( Solar Cell ) in SPICE PARK(JUL2024)Update 40 models( Solar Cell ) in SPICE PARK(JUL2024)
Update 40 models( Solar Cell ) in SPICE PARK(JUL2024)
Tsuyoshi Horigome
 
🔥Young College Call Girls Chandigarh 💯Call Us 🔝 7737669865 🔝💃Independent Chan...
🔥Young College Call Girls Chandigarh 💯Call Us 🔝 7737669865 🔝💃Independent Chan...🔥Young College Call Girls Chandigarh 💯Call Us 🔝 7737669865 🔝💃Independent Chan...
🔥Young College Call Girls Chandigarh 💯Call Us 🔝 7737669865 🔝💃Independent Chan...
sonamrawat5631
 
❣Independent Call Girls Chennai 💯Call Us 🔝 7737669865 🔝💃Independent Chennai E...
❣Independent Call Girls Chennai 💯Call Us 🔝 7737669865 🔝💃Independent Chennai E...❣Independent Call Girls Chennai 💯Call Us 🔝 7737669865 🔝💃Independent Chennai E...
❣Independent Call Girls Chennai 💯Call Us 🔝 7737669865 🔝💃Independent Chennai E...
nainakaoornoida
 
MODULE 5 BIOLOGY FOR ENGINEERS TRENDS IN BIO ENGINEERING.pptx
MODULE 5 BIOLOGY FOR ENGINEERS TRENDS IN BIO ENGINEERING.pptxMODULE 5 BIOLOGY FOR ENGINEERS TRENDS IN BIO ENGINEERING.pptx
MODULE 5 BIOLOGY FOR ENGINEERS TRENDS IN BIO ENGINEERING.pptx
NaveenNaveen726446
 
Call Girls Chennai +91-8824825030 Vip Call Girls Chennai
Call Girls Chennai +91-8824825030 Vip Call Girls ChennaiCall Girls Chennai +91-8824825030 Vip Call Girls Chennai
Call Girls Chennai +91-8824825030 Vip Call Girls Chennai
paraasingh12 #V08
 
Cuttack Call Girls 💯Call Us 🔝 7374876321 🔝 💃 Independent Female Escort Service
Cuttack Call Girls 💯Call Us 🔝 7374876321 🔝 💃 Independent Female Escort ServiceCuttack Call Girls 💯Call Us 🔝 7374876321 🔝 💃 Independent Female Escort Service
Cuttack Call Girls 💯Call Us 🔝 7374876321 🔝 💃 Independent Female Escort Service
yakranividhrini
 
Call Girls Chandigarh 🔥 7014168258 🔥 Real Fun With Sexual Girl Available 24/7...
Call Girls Chandigarh 🔥 7014168258 🔥 Real Fun With Sexual Girl Available 24/7...Call Girls Chandigarh 🔥 7014168258 🔥 Real Fun With Sexual Girl Available 24/7...
Call Girls Chandigarh 🔥 7014168258 🔥 Real Fun With Sexual Girl Available 24/7...
shourabjaat424
 
🔥 Hyderabad Call Girls  👉 9352988975 👫 High Profile Call Girls Whatsapp Numbe...
🔥 Hyderabad Call Girls  👉 9352988975 👫 High Profile Call Girls Whatsapp Numbe...🔥 Hyderabad Call Girls  👉 9352988975 👫 High Profile Call Girls Whatsapp Numbe...
🔥 Hyderabad Call Girls  👉 9352988975 👫 High Profile Call Girls Whatsapp Numbe...
aarusi sexy model
 
🔥Independent Call Girls In Pune 💯Call Us 🔝 7014168258 🔝💃Independent Pune Esco...
🔥Independent Call Girls In Pune 💯Call Us 🔝 7014168258 🔝💃Independent Pune Esco...🔥Independent Call Girls In Pune 💯Call Us 🔝 7014168258 🔝💃Independent Pune Esco...
🔥Independent Call Girls In Pune 💯Call Us 🔝 7014168258 🔝💃Independent Pune Esco...
AK47
 
High Profile Call Girls Ahmedabad 🔥 7737669865 🔥 Real Fun With Sexual Girl Av...
High Profile Call Girls Ahmedabad 🔥 7737669865 🔥 Real Fun With Sexual Girl Av...High Profile Call Girls Ahmedabad 🔥 7737669865 🔥 Real Fun With Sexual Girl Av...
High Profile Call Girls Ahmedabad 🔥 7737669865 🔥 Real Fun With Sexual Girl Av...
dABGO KI CITy kUSHINAGAR Ak47
 

Recently uploaded (20)

Basic principle and types Static Relays ppt
Basic principle and  types  Static Relays pptBasic principle and  types  Static Relays ppt
Basic principle and types Static Relays ppt
 
Data Communication and Computer Networks Management System Project Report.pdf
Data Communication and Computer Networks Management System Project Report.pdfData Communication and Computer Networks Management System Project Report.pdf
Data Communication and Computer Networks Management System Project Report.pdf
 
Sachpazis_Consolidation Settlement Calculation Program-The Python Code and th...
Sachpazis_Consolidation Settlement Calculation Program-The Python Code and th...Sachpazis_Consolidation Settlement Calculation Program-The Python Code and th...
Sachpazis_Consolidation Settlement Calculation Program-The Python Code and th...
 
Call Girls In Tiruppur 👯‍♀️ 7339748667 🔥 Free Home Delivery Within 30 Minutes
Call Girls In Tiruppur 👯‍♀️ 7339748667 🔥 Free Home Delivery Within 30 MinutesCall Girls In Tiruppur 👯‍♀️ 7339748667 🔥 Free Home Delivery Within 30 Minutes
Call Girls In Tiruppur 👯‍♀️ 7339748667 🔥 Free Home Delivery Within 30 Minutes
 
Call Girls In Lucknow 🔥 +91-7014168258🔥High Profile Call Girl Lucknow
Call Girls In Lucknow 🔥 +91-7014168258🔥High Profile Call Girl LucknowCall Girls In Lucknow 🔥 +91-7014168258🔥High Profile Call Girl Lucknow
Call Girls In Lucknow 🔥 +91-7014168258🔥High Profile Call Girl Lucknow
 
Online train ticket booking system project.pdf
Online train ticket booking system project.pdfOnline train ticket booking system project.pdf
Online train ticket booking system project.pdf
 
Call Girls Madurai 8824825030 Escort In Madurai service 24X7
Call Girls Madurai 8824825030 Escort In Madurai service 24X7Call Girls Madurai 8824825030 Escort In Madurai service 24X7
Call Girls Madurai 8824825030 Escort In Madurai service 24X7
 
Cricket management system ptoject report.pdf
Cricket management system ptoject report.pdfCricket management system ptoject report.pdf
Cricket management system ptoject report.pdf
 
INTRODUCTION TO ARTIFICIAL INTELLIGENCE BASIC
INTRODUCTION TO ARTIFICIAL INTELLIGENCE BASICINTRODUCTION TO ARTIFICIAL INTELLIGENCE BASIC
INTRODUCTION TO ARTIFICIAL INTELLIGENCE BASIC
 
一比一原版(UO毕业证)渥太华大学毕业证如何办理
一比一原版(UO毕业证)渥太华大学毕业证如何办理一比一原版(UO毕业证)渥太华大学毕业证如何办理
一比一原版(UO毕业证)渥太华大学毕业证如何办理
 
Update 40 models( Solar Cell ) in SPICE PARK(JUL2024)
Update 40 models( Solar Cell ) in SPICE PARK(JUL2024)Update 40 models( Solar Cell ) in SPICE PARK(JUL2024)
Update 40 models( Solar Cell ) in SPICE PARK(JUL2024)
 
🔥Young College Call Girls Chandigarh 💯Call Us 🔝 7737669865 🔝💃Independent Chan...
🔥Young College Call Girls Chandigarh 💯Call Us 🔝 7737669865 🔝💃Independent Chan...🔥Young College Call Girls Chandigarh 💯Call Us 🔝 7737669865 🔝💃Independent Chan...
🔥Young College Call Girls Chandigarh 💯Call Us 🔝 7737669865 🔝💃Independent Chan...
 
❣Independent Call Girls Chennai 💯Call Us 🔝 7737669865 🔝💃Independent Chennai E...
❣Independent Call Girls Chennai 💯Call Us 🔝 7737669865 🔝💃Independent Chennai E...❣Independent Call Girls Chennai 💯Call Us 🔝 7737669865 🔝💃Independent Chennai E...
❣Independent Call Girls Chennai 💯Call Us 🔝 7737669865 🔝💃Independent Chennai E...
 
MODULE 5 BIOLOGY FOR ENGINEERS TRENDS IN BIO ENGINEERING.pptx
MODULE 5 BIOLOGY FOR ENGINEERS TRENDS IN BIO ENGINEERING.pptxMODULE 5 BIOLOGY FOR ENGINEERS TRENDS IN BIO ENGINEERING.pptx
MODULE 5 BIOLOGY FOR ENGINEERS TRENDS IN BIO ENGINEERING.pptx
 
Call Girls Chennai +91-8824825030 Vip Call Girls Chennai
Call Girls Chennai +91-8824825030 Vip Call Girls ChennaiCall Girls Chennai +91-8824825030 Vip Call Girls Chennai
Call Girls Chennai +91-8824825030 Vip Call Girls Chennai
 
Cuttack Call Girls 💯Call Us 🔝 7374876321 🔝 💃 Independent Female Escort Service
Cuttack Call Girls 💯Call Us 🔝 7374876321 🔝 💃 Independent Female Escort ServiceCuttack Call Girls 💯Call Us 🔝 7374876321 🔝 💃 Independent Female Escort Service
Cuttack Call Girls 💯Call Us 🔝 7374876321 🔝 💃 Independent Female Escort Service
 
Call Girls Chandigarh 🔥 7014168258 🔥 Real Fun With Sexual Girl Available 24/7...
Call Girls Chandigarh 🔥 7014168258 🔥 Real Fun With Sexual Girl Available 24/7...Call Girls Chandigarh 🔥 7014168258 🔥 Real Fun With Sexual Girl Available 24/7...
Call Girls Chandigarh 🔥 7014168258 🔥 Real Fun With Sexual Girl Available 24/7...
 
🔥 Hyderabad Call Girls  👉 9352988975 👫 High Profile Call Girls Whatsapp Numbe...
🔥 Hyderabad Call Girls  👉 9352988975 👫 High Profile Call Girls Whatsapp Numbe...🔥 Hyderabad Call Girls  👉 9352988975 👫 High Profile Call Girls Whatsapp Numbe...
🔥 Hyderabad Call Girls  👉 9352988975 👫 High Profile Call Girls Whatsapp Numbe...
 
🔥Independent Call Girls In Pune 💯Call Us 🔝 7014168258 🔝💃Independent Pune Esco...
🔥Independent Call Girls In Pune 💯Call Us 🔝 7014168258 🔝💃Independent Pune Esco...🔥Independent Call Girls In Pune 💯Call Us 🔝 7014168258 🔝💃Independent Pune Esco...
🔥Independent Call Girls In Pune 💯Call Us 🔝 7014168258 🔝💃Independent Pune Esco...
 
High Profile Call Girls Ahmedabad 🔥 7737669865 🔥 Real Fun With Sexual Girl Av...
High Profile Call Girls Ahmedabad 🔥 7737669865 🔥 Real Fun With Sexual Girl Av...High Profile Call Girls Ahmedabad 🔥 7737669865 🔥 Real Fun With Sexual Girl Av...
High Profile Call Girls Ahmedabad 🔥 7737669865 🔥 Real Fun With Sexual Girl Av...
 

The Phases of a Compiler

  • 1. SHREE SWAMI ATMANAND SARASWATI INSTITUTE OF TECHNOLOGY Compiler Design(2170701) PREPARED BY: (Group:1) Bhumi Aghera(130760107001) Monika Dudhat(130760107007) Radhika Talaviya(130760107029) Rajvi Vaghasiya(130760107031) The Phases of a Compiler GUIDED BY: Prof. Akhilesh Ladha
  • 2. Language Processing System • We have learnt that any computer system is made of hardware and software. • The hardware understands a language, which humans cannot understand. So we write programs in high-level language, which is easier for us to understand and remember. • These programs are then fed into a series of tools and OS components to get the desired code that can be used by the machine. • This is known as Language Processing System.
  • 4. Phases of Compiler • There are mainly two parts of compilation process. 1. Analysis phase 2. Synthesis phase 1. Analysis phase: The main objective of the Analysis phase is to break the source code into parts and then arranges these pieces into a meaningful structure. • The analysis phase also collect information about source program and stores it in a data structure called symbol table. • The analysis phase is often called the front end of compiler. • Analysis phase contains: I. Lexical analysis II. Syntax analysis III. Semantic analysis
  • 5. 2. Synthesis phase: Synthesis phase is concerned with generation of target language statement which has the same meaning as the source statement. • The synthesis phase is often called the back end of compiler. • Synthesis phase contains: I. Intermediate code generation II. Code optimization III. Code generation Phases of Compiler
  • 7. Lexical Analysis • The first phase of a compiler is called lexical analysis or scanning. • The lexical analyzer takes the modified source code from language preprocessors that are written in the form of sentences. • The lexical analyzer reads the stream of characters making up the source program and groups the characters into meaningful sequences called lexemes. • Lexical analyzer represents these lexemes in the form of tokens as: <token-name, attribute-value> where, token-name: an abstract symbol is used during syntax analysis. attribute-value: points to an entry in the symbol table for this token. Lexical analysisInput string Tokens or lexemes
  • 8. Tokens, Patterns And Lexemes Token: Token is a sequence of characters that can be treated as a single logical entity. Typical tokens are, Identifiers keywords operators special symbols constants Pattern: A set of strings in the input for which the same token is produced as output. This set of strings is described by a rule called a pattern associated with the token. Lexeme: A lexeme is a sequence of characters in the source program that is matched by the pattern for a token.
  • 9. Tokenization • Process of forming tokens from input stream is called tokenization. div = 6/2; Lexeme Token div Identifier = Assignment symbol 6 Number / Division operator 2 Number ; End of statement
  • 10. Type Example Comment /* ignored */ Preprocessor directive #include<stdio.h> #define NUMS 5 Macro NUMS whitespace t n b Type Example ID foo n_14 last NUM 73 00 517 082 REAL 66.1 .5 10. 1e67 5.5e-10 COMMA , NOTEQ != LPAREN ( RPAREN ) Examples of tokens Example of non-tokens
  • 11. Tasks – lexical analyzer • Separation of the input source code into tokens. • Remove the unnecessary white spaces from the source code. • Removing the comments from the source text. • Keeping track of line numbers while scanning the new line characters. These line numbers are used by the error handler to print the error messages. • Preprocessing of macros.
  • 12. Syntax Analysis • The second phase of the compiler is called the syntax analysis or parsing. • It takes the token produced by lexical analysis as input and generates a parse tree (or syntax tree). • The parser uses the first components of the tokens produced by the lexical analyzer to create a tree-like intermediate representation that depicts the grammatical structure of the token stream. • A typical representation is a syntax tree in which each interior node represents an operation and the children of the node represent the arguments of the operation. • In this phase, token arrangements are checked against the source code grammar, i.e. the parser checks if the expression made by the tokens is syntactically correct.
  • 13. Parse tree • It shows how the start symbol of a grammar derives a string in the language • root is labeled by the start symbol • leaf nodes are labeled by tokens • Each internal node is labeled by a non terminal • if A is a non-terminal labeling an internal node and x1, x2, …xn are labels of children of that node then A  x1 x2 … xn is a production • For example, Parse tree for 9-5+2 list list list digit digit + - digit 9 5 2
  • 14. Semantic Analysis • The semantic analyzer uses the syntax tree and the information in the symbol table to check the source program for semantic consistency with the language definition. • It also gathers type information and saves it in either the syntax tree or the symbol table, for subsequent use during intermediate-code generation. • An important part of semantic analysis is type checking, where the compiler checks that each operator has matching operands. • For example, many programming language definitions require an array index to be an integer; the compiler must report an error if a floating-point number is used to index an array. • The language specification may permit some type conversions called coercions.
  • 15. Semantic Analysis • For example, a binary arithmetic operator may be applied to either a pair of integers or to a pair of floating point numbers. If the operator is applied to a floating-point number and an integer, the compiler may convert or coerce the integer to a floating-point number. As shown in figure given below: position = initial + rate * 60 = <id,1> + <id,2> * <id,3> 60 = <id,1> + <id,2> * <id,3> digit 60 Syntax Tree Semantic Tree
  • 16. Intermediate Code Generation • In the process of translating a source program into target code, a compiler may construct one or more intermediate representation; they are commonly used during syntax and semantic analysis. • After syntax and semantic analysis of the source program, many compilers generate an explicit low-level or machine-like intermediate representation. • This intermediate representation should have two important properties: 1. It should be easy to produce. 2. It should be easy to translate into the target machine.
  • 17. Intermediate Code Generation • The considered intermediate form called three-address code, which consists of a sequence of assembly-like instructions with three operands per instruction. • Each operand can act like a register. • Three address code sequence of intermediate code generator is as follows: position = initial + rate * 60 Three-address code: t1 = inttofloat(60) t2 = id3 * t1 t3 = id2 + t2 id1 = t3 • Each three-address assignment instruction has at most one operator on the right side. These instructions fix the order in which operations to be done.
  • 18. Code Optimization • The next phase does code optimization of the intermediate code. • Optimization can be assumed as something that removes unnecessary code lines, and arranges the sequence of statements in order to speed up the program execution without wasting resources (CPU, memory) and deliver high speed • In optimization, high-level general programming constructs are replaced by very efficient low-level programming codes. • A code optimizing process must follow the three rules given below: • The output code must not, in any way, change the meaning of the program. • Optimization should increase the speed of the program and if possible, the program should demand less number of resources. • Optimization should itself be fast and should not delay the overall compiling process.
  • 19. Code Optimization • Efforts for an optimized code can be made at various levels of compiling the process. • At the beginning, users can change/rearrange the code or use better algorithms to write the code. • After generating intermediate code, the compiler can modify the intermediate code by address calculations and improving loops. • While producing the target machine code, the compiler can make use of memory hierarchy and CPU registers. • Optimization can be categorized broadly into two types : 1) Machine independent 2) Machine dependent.
  • 20. Machine-independent Optimization • In this optimization, the compiler takes in the intermediate code and transforms a part of the code that does not involve any CPU registers and/or absolute memory locations. • For example: do{ i=10; v=v+i; }while(v<10); • This code involves repeated assignment of the identifier i, which if we put this way: i=10; do{ v=v+i; }while(v<10);
  • 21. Machine-dependent Optimization • Machine-dependent optimization is done after the target code has been generated and when the code is transformed according to the target machine architecture. • It involves CPU registers and may have absolute memory references rather than relative references. Machine-dependent optimizers put efforts to take maximum advantage of memory hierarchy.
  • 22. • Code generation can be considered as the final phase of compilation. • In this phase, the code generator takes the optimized representation of the intermediate code and maps it to the target machine language. • The code generator translates the intermediate code into a sequence of (generally) re- locatable machine code. Sequence of instructions of machine code performs the task as the intermediate code would do. • Through post code generation, optimization process can be applied on the code, but that can be seen as a part of code generation phase itself. • The code generated by the compiler is an object code of some lower-level programming language, for example, assembly language. • The source code written in a higher-level language is transformed into a lower-level language that results in a lower-level object code, which should have the following minimum properties: • It should carry the exact meaning of the source code. • It should be efficient in terms of CPU usage and memory management. Code Generation
  翻译: