SlideShare une entreprise Scribd logo
1  sur  22
By
Abhishek Singh
Computer Sc. Department
 Introduction to Translator.
 Assembler.
 Interpreter.
 Compiler.
 Phases of Compiler.
 Example
Created By Abhishek Singh 2
 Translator is system software which translate source
language into target language.
 Translator are of three type:-
Assembler.
Interpreter.
Compiler.
Created By Abhishek Singh 3
 Assembler translates an assembly language program
(the source program) to the machine language
program (the object program).
 Assembly language use Mnemonics like ADD,MULT
etc.
 Form example:- MOV R1,a
Created By
Abhishek Singh 4
Assembler
Assembly
Language
Machine
Language
 Interpreter translates a program line-by-line
(statement-by-statement) and carries out the specified
actions according to input.
Created By Abhishek Singh 5
Interpreter
Source
Program
Input
Output
Error messages
 Compiler is a system software, which translates a
program written in a source language into an
equivalent program in a target language.
Created By Abhishek Singh 6
Compiler
Error messages
Source
Program
Target
Program
Input
Output
 Compiler have six phase.
1. Lexical Analysis.
2. Syntax Analysis.
3. Semantic Analysis.
4. Intermediate Code Generation.
5. Code Optimization.
6. Code Generation.
Created By Abhishek Singh 7
 In this phase of compilation full source code is
scanned and program is broken up into groups of
string called token.
 Token is a sequence of characters having a collective
meaning.
 For example:-
◦ total = count + rate * 10
Created By Abhishek Singh 8
total = count + rate * 10
 In this phase token generated by lexical analyses are
grouped together to form a hierarchical structure.
 The structure is known syntax tree. For building
syntax tree the production rules are designed. These
rule are according to Grammar.
 Let take Grammar for total = count + rate * 10
 E<- id
 E<-number
 E<-E1 + E2
 E<-E1 * E2
 E<-(E)
Created By Abhishek Singh 9
Created By Abhishek Singh 10
total
=
+
*count
rate 10
 Semantic analysis is a phase of compiler that adds
semantical information to the parse tree and performs
certain checks based on this information.
 For a program to be semantically valid mean, all
variables, functions, classes, etc. must be properly
defined.
Created By Abhishek Singh 11
Created By Abhishek Singh 12
total
=
+
*count
rate int to real
10
 This is a kind of code which is easy to generate and easily
converted to target code.
 This code is in form like three address code.
 For example
 Intermediate for total = count + rate * 10
 Here t1,t2 and t3 are temporary variable.
 t1 := int to real (10)
 t2 := rate * t1
 t3 := count + t2
 total := t3
Created By Abhishek Singh 13
 The code optimization phase attempts to improve the
intermediate code, this phase increase the execution
speed and less consumption of memory.
◦ Optimize code for code total = count + rate * 10 is
 t1 := rate * 10.0
 total := count + t1
Created By Abhishek Singh 14
 In this phase target code gets generated. The code
optimization phase instructions are translated into
sequence of target code.
 Generated code is:-
◦ MOV R1,rate
◦ MUL R1,10.0
◦ MOV R2, count
◦ ADD R1,R2
◦ MOV total,R1
Created By Abhishek Singh 15
 The main utility of a compiler is to record the
variable names used in the source program and gather
information about different attributes of each
variable.
 These attributes can provide the information about
the storage allocation for name, its type, its scope
(where we use this value in program), and in the case
of function or subprogram, its name, number and
types of its arguments, the method of passing each
argument (like, by value or by reference), and the
type returns.
Created By Abhishek Singh 16
 Mainly compilation error are gather in:-
1. Lexical Errors :-Lexical phase detect errors of inputs
such as illegal characters , End of line mark missing in
strings.
2. Syntactical Errors :- Syntactical phase detect errors of
syntax like, Incorrect sequence of tokens, Misspelled
keywords (e.g. TEHN).
3. Semantical Errors :-Semantical phase detect errors of
meaning like, Incorrect composition of types,
Multiple declaration of a variable and Variable use
before assignment.
Created By Abhishek Singh 17
Created By Abhishek Singh 18
Lexical Analysis
Syntax Analysis
Semantic Analysis
Source Program
Total=count + rate* 10;
Token
stream total = count + rate * 10
=
total +
*count
rate 10
Syntax
Tree
Semantic
Tree
total
=
+
*count
rate int to real
10
Created By Abhishek Singh 19
Intermediate Code
Generation
Code Optimization
Code Generation
10
total
=
+
*count
rate int to real
t1 := int to real (10)
t2 := rate * t1
t3 := count + t2
total := t3
Semantic
Tree
Intermediate
Code
Target
Code
Optimize
Code t1 := rate * 10
total := count + t1
MOV rate,R1
MUL #10.0, R1
MOV count, R2
ADD R2,R1
MOV R1,total
Created By Abhishek Singh 20
Editor Compiler Assembler
Linker
LoaderDebugger
Programmer
Source
Program
Assembly
Code
Machine
Code
Linking
Programmer
Does manual
Correction of
the code
Debugging
Results
Debug if Error
Executable
Image
Created By Abhishek Singh 21
Created By Abhishek Singh 22

Contenu connexe

Tendances

Intermediate code- generation
Intermediate code- generationIntermediate code- generation
Intermediate code- generation
rawan_z
 
Error detection recovery
Error detection recoveryError detection recovery
Error detection recovery
Tech_MX
 
Introduction to compiler
Introduction to compilerIntroduction to compiler
Introduction to compiler
Abha Damani
 

Tendances (20)

Compiler construction tools
Compiler construction toolsCompiler construction tools
Compiler construction tools
 
Three Address code
Three Address code Three Address code
Three Address code
 
Phases of compiler
Phases of compilerPhases of compiler
Phases of compiler
 
Basic blocks - compiler design
Basic blocks - compiler designBasic blocks - compiler design
Basic blocks - compiler design
 
Intermediate code- generation
Intermediate code- generationIntermediate code- generation
Intermediate code- generation
 
Algorithm and flowchart
Algorithm and flowchartAlgorithm and flowchart
Algorithm and flowchart
 
Intermediate code generation in Compiler Design
Intermediate code generation in Compiler DesignIntermediate code generation in Compiler Design
Intermediate code generation in Compiler Design
 
COMPILER DESIGN
COMPILER DESIGNCOMPILER DESIGN
COMPILER DESIGN
 
Control Flow Graphs
Control Flow GraphsControl Flow Graphs
Control Flow Graphs
 
Programming Fundamental Presentation
Programming Fundamental PresentationProgramming Fundamental Presentation
Programming Fundamental Presentation
 
Compiler Design Unit 1
Compiler Design Unit 1Compiler Design Unit 1
Compiler Design Unit 1
 
Error detection recovery
Error detection recoveryError detection recovery
Error detection recovery
 
Recursion tree method
Recursion tree methodRecursion tree method
Recursion tree method
 
Compiler type
Compiler typeCompiler type
Compiler type
 
Intermediate code generation (Compiler Design)
Intermediate code generation (Compiler Design)   Intermediate code generation (Compiler Design)
Intermediate code generation (Compiler Design)
 
Parsing in Compiler Design
Parsing in Compiler DesignParsing in Compiler Design
Parsing in Compiler Design
 
Top down parsing
Top down parsingTop down parsing
Top down parsing
 
Lecture 04 syntax analysis
Lecture 04 syntax analysisLecture 04 syntax analysis
Lecture 04 syntax analysis
 
Code Optimization
Code OptimizationCode Optimization
Code Optimization
 
Introduction to compiler
Introduction to compilerIntroduction to compiler
Introduction to compiler
 

Similaire à Basic of compiler

1 - Introduction to Compilers.ppt
1 - Introduction to Compilers.ppt1 - Introduction to Compilers.ppt
1 - Introduction to Compilers.ppt
Rakesh Kumar
 
Chapter One
Chapter OneChapter One
Chapter One
bolovv
 
2-Design Issues, Patterns, Lexemes, Tokens-28-04-2023.docx
2-Design Issues, Patterns, Lexemes, Tokens-28-04-2023.docx2-Design Issues, Patterns, Lexemes, Tokens-28-04-2023.docx
2-Design Issues, Patterns, Lexemes, Tokens-28-04-2023.docx
venkatapranaykumarGa
 

Similaire à Basic of compiler (20)

unit1pdf__2021_12_14_12_37_34.pdf
unit1pdf__2021_12_14_12_37_34.pdfunit1pdf__2021_12_14_12_37_34.pdf
unit1pdf__2021_12_14_12_37_34.pdf
 
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
 
Compiler
Compiler Compiler
Compiler
 
Chapter#01 cc
Chapter#01 ccChapter#01 cc
Chapter#01 cc
 
How a Compiler Works ?
How a Compiler Works ?How a Compiler Works ?
How a Compiler Works ?
 
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
 
Concept of compiler in details
Concept of compiler in detailsConcept of compiler in details
Concept of compiler in details
 
3.2
3.23.2
3.2
 
Compiler Design
Compiler DesignCompiler Design
Compiler Design
 
1 - Introduction to Compilers.ppt
1 - Introduction to Compilers.ppt1 - Introduction to Compilers.ppt
1 - Introduction to Compilers.ppt
 
Assignment1
Assignment1Assignment1
Assignment1
 
Chapter One
Chapter OneChapter One
Chapter One
 
Introduction to Compilers
Introduction to CompilersIntroduction to Compilers
Introduction to Compilers
 
Chapter-1.pptx compiler Design Course Material
Chapter-1.pptx compiler Design Course MaterialChapter-1.pptx compiler Design Course Material
Chapter-1.pptx compiler Design Course Material
 
Phases of Compiler.pptx
Phases of Compiler.pptxPhases of Compiler.pptx
Phases of Compiler.pptx
 
2-Design Issues, Patterns, Lexemes, Tokens-28-04-2023.docx
2-Design Issues, Patterns, Lexemes, Tokens-28-04-2023.docx2-Design Issues, Patterns, Lexemes, Tokens-28-04-2023.docx
2-Design Issues, Patterns, Lexemes, Tokens-28-04-2023.docx
 
basics of compiler design
basics of compiler designbasics of compiler design
basics of compiler design
 
Compiler Construction introduction
Compiler Construction introductionCompiler Construction introduction
Compiler Construction introduction
 
The Phases of a Compiler
The Phases of a CompilerThe Phases of a Compiler
The Phases of a Compiler
 
Lexical analyzer
Lexical analyzerLexical analyzer
Lexical analyzer
 

Dernier

notes on Evolution Of Analytic Scalability.ppt
notes on Evolution Of Analytic Scalability.pptnotes on Evolution Of Analytic Scalability.ppt
notes on Evolution Of Analytic Scalability.ppt
MsecMca
 
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
dollysharma2066
 
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
ssuser89054b
 
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
dharasingh5698
 
Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night StandCall Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Stand
amitlee9823
 
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
dharasingh5698
 
Call Girls in Netaji Nagar, Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Netaji Nagar, Delhi 💯 Call Us 🔝9953056974 🔝 Escort ServiceCall Girls in Netaji Nagar, Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Netaji Nagar, Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 

Dernier (20)

chapter 5.pptx: drainage and irrigation engineering
chapter 5.pptx: drainage and irrigation engineeringchapter 5.pptx: drainage and irrigation engineering
chapter 5.pptx: drainage and irrigation engineering
 
Block diagram reduction techniques in control systems.ppt
Block diagram reduction techniques in control systems.pptBlock diagram reduction techniques in control systems.ppt
Block diagram reduction techniques in control systems.ppt
 
notes on Evolution Of Analytic Scalability.ppt
notes on Evolution Of Analytic Scalability.pptnotes on Evolution Of Analytic Scalability.ppt
notes on Evolution Of Analytic Scalability.ppt
 
UNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its PerformanceUNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its Performance
 
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
 
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
 
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
 
Unit 1 - Soil Classification and Compaction.pdf
Unit 1 - Soil Classification and Compaction.pdfUnit 1 - Soil Classification and Compaction.pdf
Unit 1 - Soil Classification and Compaction.pdf
 
Intro To Electric Vehicles PDF Notes.pdf
Intro To Electric Vehicles PDF Notes.pdfIntro To Electric Vehicles PDF Notes.pdf
Intro To Electric Vehicles PDF Notes.pdf
 
Bhosari ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready For ...
Bhosari ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready For ...Bhosari ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready For ...
Bhosari ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready For ...
 
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
 
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
 
Booking open Available Pune Call Girls Pargaon 6297143586 Call Hot Indian Gi...
Booking open Available Pune Call Girls Pargaon  6297143586 Call Hot Indian Gi...Booking open Available Pune Call Girls Pargaon  6297143586 Call Hot Indian Gi...
Booking open Available Pune Call Girls Pargaon 6297143586 Call Hot Indian Gi...
 
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordCCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
 
Thermal Engineering Unit - I & II . ppt
Thermal Engineering  Unit - I & II . pptThermal Engineering  Unit - I & II . ppt
Thermal Engineering Unit - I & II . ppt
 
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
 
Work-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptxWork-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptx
 
Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night StandCall Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Stand
 
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
 
Call Girls in Netaji Nagar, Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Netaji Nagar, Delhi 💯 Call Us 🔝9953056974 🔝 Escort ServiceCall Girls in Netaji Nagar, Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Netaji Nagar, Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
 

Basic of compiler

  • 2.  Introduction to Translator.  Assembler.  Interpreter.  Compiler.  Phases of Compiler.  Example Created By Abhishek Singh 2
  • 3.  Translator is system software which translate source language into target language.  Translator are of three type:- Assembler. Interpreter. Compiler. Created By Abhishek Singh 3
  • 4.  Assembler translates an assembly language program (the source program) to the machine language program (the object program).  Assembly language use Mnemonics like ADD,MULT etc.  Form example:- MOV R1,a Created By Abhishek Singh 4 Assembler Assembly Language Machine Language
  • 5.  Interpreter translates a program line-by-line (statement-by-statement) and carries out the specified actions according to input. Created By Abhishek Singh 5 Interpreter Source Program Input Output Error messages
  • 6.  Compiler is a system software, which translates a program written in a source language into an equivalent program in a target language. Created By Abhishek Singh 6 Compiler Error messages Source Program Target Program Input Output
  • 7.  Compiler have six phase. 1. Lexical Analysis. 2. Syntax Analysis. 3. Semantic Analysis. 4. Intermediate Code Generation. 5. Code Optimization. 6. Code Generation. Created By Abhishek Singh 7
  • 8.  In this phase of compilation full source code is scanned and program is broken up into groups of string called token.  Token is a sequence of characters having a collective meaning.  For example:- ◦ total = count + rate * 10 Created By Abhishek Singh 8 total = count + rate * 10
  • 9.  In this phase token generated by lexical analyses are grouped together to form a hierarchical structure.  The structure is known syntax tree. For building syntax tree the production rules are designed. These rule are according to Grammar.  Let take Grammar for total = count + rate * 10  E<- id  E<-number  E<-E1 + E2  E<-E1 * E2  E<-(E) Created By Abhishek Singh 9
  • 10. Created By Abhishek Singh 10 total = + *count rate 10
  • 11.  Semantic analysis is a phase of compiler that adds semantical information to the parse tree and performs certain checks based on this information.  For a program to be semantically valid mean, all variables, functions, classes, etc. must be properly defined. Created By Abhishek Singh 11
  • 12. Created By Abhishek Singh 12 total = + *count rate int to real 10
  • 13.  This is a kind of code which is easy to generate and easily converted to target code.  This code is in form like three address code.  For example  Intermediate for total = count + rate * 10  Here t1,t2 and t3 are temporary variable.  t1 := int to real (10)  t2 := rate * t1  t3 := count + t2  total := t3 Created By Abhishek Singh 13
  • 14.  The code optimization phase attempts to improve the intermediate code, this phase increase the execution speed and less consumption of memory. ◦ Optimize code for code total = count + rate * 10 is  t1 := rate * 10.0  total := count + t1 Created By Abhishek Singh 14
  • 15.  In this phase target code gets generated. The code optimization phase instructions are translated into sequence of target code.  Generated code is:- ◦ MOV R1,rate ◦ MUL R1,10.0 ◦ MOV R2, count ◦ ADD R1,R2 ◦ MOV total,R1 Created By Abhishek Singh 15
  • 16.  The main utility of a compiler is to record the variable names used in the source program and gather information about different attributes of each variable.  These attributes can provide the information about the storage allocation for name, its type, its scope (where we use this value in program), and in the case of function or subprogram, its name, number and types of its arguments, the method of passing each argument (like, by value or by reference), and the type returns. Created By Abhishek Singh 16
  • 17.  Mainly compilation error are gather in:- 1. Lexical Errors :-Lexical phase detect errors of inputs such as illegal characters , End of line mark missing in strings. 2. Syntactical Errors :- Syntactical phase detect errors of syntax like, Incorrect sequence of tokens, Misspelled keywords (e.g. TEHN). 3. Semantical Errors :-Semantical phase detect errors of meaning like, Incorrect composition of types, Multiple declaration of a variable and Variable use before assignment. Created By Abhishek Singh 17
  • 18. Created By Abhishek Singh 18 Lexical Analysis Syntax Analysis Semantic Analysis Source Program Total=count + rate* 10; Token stream total = count + rate * 10 = total + *count rate 10 Syntax Tree Semantic Tree total = + *count rate int to real 10
  • 19. Created By Abhishek Singh 19 Intermediate Code Generation Code Optimization Code Generation 10 total = + *count rate int to real t1 := int to real (10) t2 := rate * t1 t3 := count + t2 total := t3 Semantic Tree Intermediate Code Target Code Optimize Code t1 := rate * 10 total := count + t1 MOV rate,R1 MUL #10.0, R1 MOV count, R2 ADD R2,R1 MOV R1,total
  • 20. Created By Abhishek Singh 20 Editor Compiler Assembler Linker LoaderDebugger Programmer Source Program Assembly Code Machine Code Linking Programmer Does manual Correction of the code Debugging Results Debug if Error Executable Image