SlideShare a Scribd company logo
1 of 22
Compiler Design
 Group Name : Ethernet
 Topic Name : Compiler Design
 Group Member : 152-15-6232 ( Md. Touhidur Rahman )
152-15-6236 (Sree Joyanto Chandro Barmon)
152-15-6237( Tusher Chandra Ghosh)
Index
• Introduction
• Definition
• How it’s work
• Resources
• Question Session
What is a Compiler?
A compiler translate texts from one language to other
language.
Programming
Language
(Source)
Compiler
Machine
Language
(Target)
 A compiler acts as a translator,
 transforming human-oriented programming languages
into computer-oriented machine languages.
 Ignore machine-dependent details for programmer
What Do Compilers Do ?
 Compilers may generate three types of code:
 Pure Machine Code
 Machine instruction set without assuming the existence of any operating system or library.
 Mostly being OS or embedded applications.
 Augmented Machine Code
 Code with OS routines and runtime support routines.
 More often
 Virtual Machine Code
 Virtual instructions, can be run on any architecture with a virtual machine interpreter or a just-in-time comp
 Ex. Java
A Language Processing System
Major Tasks
• Any compiler must perform two major tasks
Compiler
Analysis Synthesis
• Analysis of the source program
• Synthesis of a machine-language program
The Structure of a Compiler
8
Scanner Parser
Semantic
Routines
Code
Generator
Optimizer
Source
Program Tokens Syntactic
Structure
Symbol and
Attribute
Tables
(Used by all Phases of The Compiler)
(Character Stream)
Intermediate
Representation
Target machine code
The Structure of a Compiler
9
Scanner Parser
Semantic
Routines
Code
Generator
Optimizer
Source
Program Tokens Syntactic
Structure
Symbol and
Attribute
Tables
(Used by all
Phases of
The Compiler)
Scanner
 The scanner begins the analysis of the source program
by reading the input, character by character, and
grouping characters into individual words and symbols
(tokens)
 RE ( Regular expression )
 NFA ( Non-deterministic Finite Automata )
 DFA ( Deterministic Finite Automata )
(Character Stream)
Intermediate
Representation
Target machine code
The Structure of a Compiler
10
Scanner Parser
Semantic
Routines
Code
Generator
Optimizer
Source
Program Tokens Syntactic
Structure
Symbol and
Attribute
Tables
(Used by all
Phases of
The Compiler)
Parser
 Given a formal syntax specification (typically as a context-
free grammar [CFG] ), the parse reads tokens and groups
them into units as specified by the productions of the
CFG being used.
 As syntactic structure is recognized, the parser either calls
corresponding semantic routines directly or builds a
syntax tree.
 CFG ( Context-Free Grammar )
 GAA ( Grammar Analysis Algorithms )
(Character Stream)
Intermediate
Representation
Target machine code
The Structure of a Compiler
11
Scanner Parser
Semantic
Routines
Code
Generator
Optimizer
Source
Program
(Character Stream)
Tokens Syntactic
Structure
Intermediate
Representation
Symbol and
Attribute
Tables
(Used by all
Phases of
The Compiler)
Semantic Routines
 Perform two functions
 Check the static semantics of each construct
 Do the actual translation
 The heart of a compiler
 Syntax Directed Translation
 Semantic Processing Techniques
 IR (Intermediate Representation)
Target machine code
The Structure of a Compiler
12
Scanner Parser
Semantic
Routines
Code
Generator
Optimizer
Source
Program Tokens Syntactic
Structure
Symbol and
Attribute
Tables
(Used by all
Phases of
The Compiler)
Optimizer
 The IR code generated by the semantic routines is
analyzed and transformed into functionally equivalent but
improved IR code
 This phase can be very complex and slow
 Peephole optimization
 loop optimization, register allocation, code scheduling
 Register and Temporary Management
 Peephole Optimization
(Character Stream)
Intermediate
Representation
Target machine code
The Structure of a Compiler
13
Source
Program
(Character Stream)
Scanner
Tokens
Parser
Syntactic
Structure
Semantic
Routines
Intermediate
Representation
Optimizer
Code
Generator
Code Generator
 Interpretive Code Generation
 Generating Code from Tree/Dag
 Grammar-Based Code Generator
Target machine code
The Structure of a Compiler (Example)
14
Scanner
[Lexical Analyzer]
Parser
[Syntax Analyzer]
Semantic Process
[Semantic analyzer]
Code Generator
[Intermediate Code Generator]
Code Optimizer
Tokens
Parse tree
Abstract Syntax Tree Attributes
Non-optimized Intermediate Code
Optimized Intermediate Code
Code Generator
Target machine code
LDF R2,id3
MULF R2,R2,#60.0
LDF R1,id2
ADDF R1,R1,R2
MOVF id1,R1
What is NFA and DFA
What is NFA?
 An NFA is a Nondeterministic Finite
Automaton. Nondeterministic means it
can transition to, and be in, multiple
states at once
What is DFA?
 A DFA is a Deterministic Finite
Automaton. Deterministic means that it
can only be in, and transition to, one
state at a time
Formal Definition of Nondeterministic Finite Automata.
 An NFA is a five-tuple: N = (S, ∑, δ, S0, F)
 A Finite set of state (S)
 A Set of input symbol (∑)
 A Transition Function (δ)
 The initial/starting state, S0
 A Set of final state F
Regular Expression:
State a b
1 {1,2} {1}
2 ϕ {3}
3 ϕ {4}
4 ϕ ϕ
(a|b)* abb
An NFA can easily implemented using a transition table
Now we convert the following NFA to DFA
State a b
{1} {1,2} {1}
{1,2} {1,2} {1,3}
{1,3} {1,2} {1,4}
{1,4} {1,2} {1}
Transition Table for DFA
Difference Between NFA and DFA
 NFA
 Multiple states Transition at once
 Operator Zero or More
 DFA
 only one state transition in DFA.
 Operator One or More
Resources
www.wikipedia.org
www.Google.com
www.tutorialspoint.com
www.slideshare.net
Presentation compiler design
Presentation compiler design

More Related Content

What's hot (20)

Compiler design
Compiler designCompiler design
Compiler design
 
Compiler Design
Compiler DesignCompiler Design
Compiler Design
 
Compiler Chapter 1
Compiler Chapter 1Compiler Chapter 1
Compiler Chapter 1
 
A Role of Lexical Analyzer
A Role of Lexical AnalyzerA Role of Lexical Analyzer
A Role of Lexical Analyzer
 
Compiler Design(NANTHU NOTES)
Compiler Design(NANTHU NOTES)Compiler Design(NANTHU NOTES)
Compiler Design(NANTHU NOTES)
 
COMPILER DESIGN- Introduction & Lexical Analysis:
COMPILER DESIGN- Introduction & Lexical Analysis: COMPILER DESIGN- Introduction & Lexical Analysis:
COMPILER DESIGN- Introduction & Lexical Analysis:
 
Phases of compiler
Phases of compilerPhases of compiler
Phases of compiler
 
Lexical Analysis
Lexical AnalysisLexical Analysis
Lexical Analysis
 
Phases of Compiler
Phases of CompilerPhases of Compiler
Phases of Compiler
 
Yacc
YaccYacc
Yacc
 
Non- Recursive Predictive Parsing.pptx
Non- Recursive Predictive Parsing.pptxNon- Recursive Predictive Parsing.pptx
Non- Recursive Predictive Parsing.pptx
 
compiler ppt on symbol table
 compiler ppt on symbol table compiler ppt on symbol table
compiler ppt on symbol table
 
Lexical Analysis - Compiler Design
Lexical Analysis - Compiler DesignLexical Analysis - Compiler Design
Lexical Analysis - Compiler Design
 
Compilers
CompilersCompilers
Compilers
 
Computer programing 111 lecture 1
Computer programing 111 lecture 1 Computer programing 111 lecture 1
Computer programing 111 lecture 1
 
Difference between c, c++ and java
Difference between c, c++ and javaDifference between c, c++ and java
Difference between c, c++ and java
 
Compiler design and lexical analyser
Compiler design and lexical analyserCompiler design and lexical analyser
Compiler design and lexical analyser
 
Phases of compiler
Phases of compilerPhases of compiler
Phases of compiler
 
Lex Tool
Lex ToolLex Tool
Lex Tool
 
Role-of-lexical-analysis
Role-of-lexical-analysisRole-of-lexical-analysis
Role-of-lexical-analysis
 

Similar to Presentation compiler design

Similar to Presentation compiler design (20)

Cd unit i
Cd unit iCd unit i
Cd unit i
 
Compiler
Compiler Compiler
Compiler
 
Introduction to Compilers | Phases & Structure
Introduction to Compilers | Phases & StructureIntroduction to Compilers | Phases & Structure
Introduction to Compilers | Phases & Structure
 
CD U1-5.pptx
CD U1-5.pptxCD U1-5.pptx
CD U1-5.pptx
 
1 introduction to compiler
1 introduction to compiler1 introduction to compiler
1 introduction to compiler
 
LANGUAGE TRANSLATOR
LANGUAGE TRANSLATORLANGUAGE TRANSLATOR
LANGUAGE TRANSLATOR
 
Compiler Construction introduction
Compiler Construction introductionCompiler Construction introduction
Compiler Construction introduction
 
Lexical analyzer
Lexical analyzerLexical analyzer
Lexical analyzer
 
Cpcs302 1
Cpcs302  1Cpcs302  1
Cpcs302 1
 
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
 
Lecture 1 introduction to language processors
Lecture 1  introduction to language processorsLecture 1  introduction to language processors
Lecture 1 introduction to language processors
 
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
 
1 - Introduction to Compilers.ppt
1 - Introduction to Compilers.ppt1 - Introduction to Compilers.ppt
1 - Introduction to Compilers.ppt
 
Yacc (yet another compiler compiler)
Yacc (yet another compiler compiler)Yacc (yet another compiler compiler)
Yacc (yet another compiler compiler)
 
Chapter One
Chapter OneChapter One
Chapter One
 
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
 
COMPILER CONSTRUCTION KU 1.pptx
COMPILER CONSTRUCTION KU 1.pptxCOMPILER CONSTRUCTION KU 1.pptx
COMPILER CONSTRUCTION KU 1.pptx
 
Chapter#01 cc
Chapter#01 ccChapter#01 cc
Chapter#01 cc
 
lec00-Introduction.pdf
lec00-Introduction.pdflec00-Introduction.pdf
lec00-Introduction.pdf
 

More from Md. Touhidur Rahman

More from Md. Touhidur Rahman (13)

Industrial management presentation
Industrial management presentationIndustrial management presentation
Industrial management presentation
 
Computer graphices presentation
Computer graphices presentationComputer graphices presentation
Computer graphices presentation
 
Presentation simulation
Presentation simulationPresentation simulation
Presentation simulation
 
Presentation operating system
Presentation operating systemPresentation operating system
Presentation operating system
 
Numerical presentation
Numerical presentationNumerical presentation
Numerical presentation
 
Presentation of database management system
Presentation of database management systemPresentation of database management system
Presentation of database management system
 
Computer networking presentation
Computer networking presentationComputer networking presentation
Computer networking presentation
 
Architecture presentation
Architecture presentationArchitecture presentation
Architecture presentation
 
Semiconductor
SemiconductorSemiconductor
Semiconductor
 
Data communication presentation
Data communication presentationData communication presentation
Data communication presentation
 
Theory of computing presentation
Theory of computing presentationTheory of computing presentation
Theory of computing presentation
 
Statistics presentation
Statistics presentationStatistics presentation
Statistics presentation
 
Production of Cost
Production of CostProduction of Cost
Production of Cost
 

Recently uploaded

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.pdfRagavanV2
 
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXssuser89054b
 
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance BookingCall Girls Wakad Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance Bookingroncy bisnoi
 
Thermal Engineering Unit - I & II . ppt
Thermal Engineering  Unit - I & II . pptThermal Engineering  Unit - I & II . ppt
Thermal Engineering Unit - I & II . pptDineshKumar4165
 
Unleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leapUnleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leapRishantSharmaFr
 
KubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlyKubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlysanyuktamishra911
 
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 engineeringmulugeta48
 
Generative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPTGenerative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPTbhaskargani46
 
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 ...tanu pandey
 
Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)simmis5
 
data_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdfdata_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdfJiananWang21
 
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...Call Girls in Nagpur High Profile
 
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Christo Ananth
 
Thermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - VThermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - VDineshKumar4165
 
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...ranjana rawat
 
Vivazz, Mieres Social Housing Design Spain
Vivazz, Mieres Social Housing Design SpainVivazz, Mieres Social Housing Design Spain
Vivazz, Mieres Social Housing Design Spaintimesproduction05
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Christo Ananth
 
Double Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torqueDouble Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torqueBhangaleSonal
 

Recently uploaded (20)

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
 
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
 
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort ServiceCall Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
 
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance BookingCall Girls Wakad Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance Booking
 
Thermal Engineering Unit - I & II . ppt
Thermal Engineering  Unit - I & II . pptThermal Engineering  Unit - I & II . ppt
Thermal Engineering Unit - I & II . ppt
 
Unleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leapUnleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leap
 
KubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlyKubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghly
 
Roadmap to Membership of RICS - Pathways and Routes
Roadmap to Membership of RICS - Pathways and RoutesRoadmap to Membership of RICS - Pathways and Routes
Roadmap to Membership of RICS - Pathways and Routes
 
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
 
Generative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPTGenerative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPT
 
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 ...
 
Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)
 
data_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdfdata_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdf
 
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...
 
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
 
Thermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - VThermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - V
 
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
 
Vivazz, Mieres Social Housing Design Spain
Vivazz, Mieres Social Housing Design SpainVivazz, Mieres Social Housing Design Spain
Vivazz, Mieres Social Housing Design Spain
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
 
Double Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torqueDouble Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torque
 

Presentation compiler design

  • 2.  Group Name : Ethernet  Topic Name : Compiler Design  Group Member : 152-15-6232 ( Md. Touhidur Rahman ) 152-15-6236 (Sree Joyanto Chandro Barmon) 152-15-6237( Tusher Chandra Ghosh)
  • 3. Index • Introduction • Definition • How it’s work • Resources • Question Session
  • 4. What is a Compiler? A compiler translate texts from one language to other language. Programming Language (Source) Compiler Machine Language (Target)
  • 5.  A compiler acts as a translator,  transforming human-oriented programming languages into computer-oriented machine languages.  Ignore machine-dependent details for programmer What Do Compilers Do ?  Compilers may generate three types of code:  Pure Machine Code  Machine instruction set without assuming the existence of any operating system or library.  Mostly being OS or embedded applications.  Augmented Machine Code  Code with OS routines and runtime support routines.  More often  Virtual Machine Code  Virtual instructions, can be run on any architecture with a virtual machine interpreter or a just-in-time comp  Ex. Java
  • 7. Major Tasks • Any compiler must perform two major tasks Compiler Analysis Synthesis • Analysis of the source program • Synthesis of a machine-language program
  • 8. The Structure of a Compiler 8 Scanner Parser Semantic Routines Code Generator Optimizer Source Program Tokens Syntactic Structure Symbol and Attribute Tables (Used by all Phases of The Compiler) (Character Stream) Intermediate Representation Target machine code
  • 9. The Structure of a Compiler 9 Scanner Parser Semantic Routines Code Generator Optimizer Source Program Tokens Syntactic Structure Symbol and Attribute Tables (Used by all Phases of The Compiler) Scanner  The scanner begins the analysis of the source program by reading the input, character by character, and grouping characters into individual words and symbols (tokens)  RE ( Regular expression )  NFA ( Non-deterministic Finite Automata )  DFA ( Deterministic Finite Automata ) (Character Stream) Intermediate Representation Target machine code
  • 10. The Structure of a Compiler 10 Scanner Parser Semantic Routines Code Generator Optimizer Source Program Tokens Syntactic Structure Symbol and Attribute Tables (Used by all Phases of The Compiler) Parser  Given a formal syntax specification (typically as a context- free grammar [CFG] ), the parse reads tokens and groups them into units as specified by the productions of the CFG being used.  As syntactic structure is recognized, the parser either calls corresponding semantic routines directly or builds a syntax tree.  CFG ( Context-Free Grammar )  GAA ( Grammar Analysis Algorithms ) (Character Stream) Intermediate Representation Target machine code
  • 11. The Structure of a Compiler 11 Scanner Parser Semantic Routines Code Generator Optimizer Source Program (Character Stream) Tokens Syntactic Structure Intermediate Representation Symbol and Attribute Tables (Used by all Phases of The Compiler) Semantic Routines  Perform two functions  Check the static semantics of each construct  Do the actual translation  The heart of a compiler  Syntax Directed Translation  Semantic Processing Techniques  IR (Intermediate Representation) Target machine code
  • 12. The Structure of a Compiler 12 Scanner Parser Semantic Routines Code Generator Optimizer Source Program Tokens Syntactic Structure Symbol and Attribute Tables (Used by all Phases of The Compiler) Optimizer  The IR code generated by the semantic routines is analyzed and transformed into functionally equivalent but improved IR code  This phase can be very complex and slow  Peephole optimization  loop optimization, register allocation, code scheduling  Register and Temporary Management  Peephole Optimization (Character Stream) Intermediate Representation Target machine code
  • 13. The Structure of a Compiler 13 Source Program (Character Stream) Scanner Tokens Parser Syntactic Structure Semantic Routines Intermediate Representation Optimizer Code Generator Code Generator  Interpretive Code Generation  Generating Code from Tree/Dag  Grammar-Based Code Generator Target machine code
  • 14. The Structure of a Compiler (Example) 14 Scanner [Lexical Analyzer] Parser [Syntax Analyzer] Semantic Process [Semantic analyzer] Code Generator [Intermediate Code Generator] Code Optimizer Tokens Parse tree Abstract Syntax Tree Attributes Non-optimized Intermediate Code Optimized Intermediate Code Code Generator Target machine code LDF R2,id3 MULF R2,R2,#60.0 LDF R1,id2 ADDF R1,R1,R2 MOVF id1,R1
  • 15. What is NFA and DFA What is NFA?  An NFA is a Nondeterministic Finite Automaton. Nondeterministic means it can transition to, and be in, multiple states at once What is DFA?  A DFA is a Deterministic Finite Automaton. Deterministic means that it can only be in, and transition to, one state at a time
  • 16. Formal Definition of Nondeterministic Finite Automata.  An NFA is a five-tuple: N = (S, ∑, δ, S0, F)  A Finite set of state (S)  A Set of input symbol (∑)  A Transition Function (δ)  The initial/starting state, S0  A Set of final state F
  • 17. Regular Expression: State a b 1 {1,2} {1} 2 ϕ {3} 3 ϕ {4} 4 ϕ ϕ (a|b)* abb An NFA can easily implemented using a transition table
  • 18. Now we convert the following NFA to DFA State a b {1} {1,2} {1} {1,2} {1,2} {1,3} {1,3} {1,2} {1,4} {1,4} {1,2} {1} Transition Table for DFA
  • 19. Difference Between NFA and DFA  NFA  Multiple states Transition at once  Operator Zero or More  DFA  only one state transition in DFA.  Operator One or More

Editor's Notes

  1. NOTE: To change the image on this slide, select the picture and delete it. Then click the Pictures icon in the placeholder to insert your own image.