SlideShare uma empresa Scribd logo
1 de 25
System Software (5KS03)
Unit 1 : Introduction to Compiling
Lecture : 2 Phases of a compiler,
A S Kapse,
Assistant Professor,
Department Of Computer Sci. & Engineering
Anuradha Engineering College, Chikhli
Contents…
 Introduction to Compilers
 Phases of Compiler
Objectives…
 Upon completion of this lecture, you will be able
 To understand the basics of compiler
 To understand Application of compiler
 To understand phases of compiler
Review…./ Concepts
 What do you mean by compiler?
 What do you mean by Operating System?
 What do you mean by system?
The Many Phases of a Compiler
Source Program
Lexical Analyzer
1
Syntax Analyzer
2
Semantic Analyzer
3
Intermediate
Code Generator
4
Code Optimizer
5
Code Generator
6
Target Program
Symbol-table
Manager
Error Handler
1, 2, 3 : Analysis - Our Focus
4, 5, 6 : Synthesis
Language-Processing System
Source Program
Pre-Processor
1
Compiler
2
Assembler
3
Relocatable
Machine Code
4
Loader
Link/Editor
5
Executable
Library,
relocatable
object files
 Three Phases:
 Linear / Lexical Analysis:
 L-to-r Scan to Identify Tokens
token: sequence of chars having a collective meaning
 Hierarchical Analysis:
 Grouping of Tokens Into Meaningful Collection
 Semantic Analysis:
 Checking to ensure Correctness of Components
The Analysis Task For Compilation
Phase 1. Lexical Analysis
Easiest Analysis - Identify tokens which are
the basic building blocks
For
Example:
All are tokens
Blanks, Line breaks, etc. are scanned out
Position := initial + rate * 60 ;
_______ __ _____ _ ___ _ __ _
Phase 2. Hierarchical Analysis
aka Parsing or Syntax Analysis
For previous example,
we would have
Parse Tree:
identifier
identifier
expression
identifier
expression
number
expression
expression
expression
assignment
statement
position
:=
+
*
60
initial
rate
Nodes of tree are constructed using a grammar for the language
What is a Grammar?
 Grammar is a Set of Rules Which Govern the
Interdependencies & Structure Among the Tokens
statement is an assignment statement, or
while statement, or if
statement, or ...
assignment statement
expression is an
is an identifier := expression ;
(expression), or expression +
expression, or expression *
expression, or number, or
identifier, or ...
Why Have We Divided Analysis
in This Manner?
 Lexical Analysis - Scans Input, Its Linear Actions Are
Not Recursive
 Identify Only Individual “words” that are the the Tokens of
the Language
 Recursion Is Required to Identify Structure of an
Expression, As Indicated in Parse Tree
 Verify that the “words” are Correctly Assembled into
“sentences”
 What is Third Phase?
 Determine Whether the Sentences have One and Only
One Unambiguous Interpretation
 … and do something about it!
 e.g. “John Took Picture of Mary Out on the Patio”
Phase 3. Semantic Analysis
 Find More Complicated Semantic Errors and
Support Code Generation
 Parse Tree Is Augmented With Semantic Actions
position
initial
rate
:=
+
*
60
Compressed Tree
position
initial
rate
:=
+
*
inttoreal
60
Conversion Action
Phase 3. Semantic Analysis
 Most Important Activity in This Phase:
 Type Checking - Legality of Operands
 Many Different Situations:
Real := int + char ;
A[int] := A[real] + int ;
while char <> int do
…. Etc.
Supporting Phases/
Activities for Analysis
 Symbol Table Creation / Maintenance
 Contains Info (storage, type, scope, args) on Each
“Meaningful” Token, Typically Identifiers
 Data Structure Created / Initialized During Lexical
Analysis
 Utilized / Updated During Later Analysis & Synthesis
 Error Handling
 Detection of Different Errors Which Correspond to All
Phases
 What Kinds of Errors Are Found During the Analysis
Phase?
 What Happens When an Error Is Found?
The Synthesis Task For Compilation
 Intermediate Code Generation
 Abstract Machine Version of Code - Independent of
Architecture
 Easy to Produce and Do Final, Machine Dependent
Code Generation
 Code Optimization
 Find More Efficient Ways to Execute Code
 Replace Code With More Optimal Statements
 2-approaches: High-level Language & “Peephole”
Optimization
 Final Code Generation
 Generate Relocatable Machine Dependent Code
The Structure of a Compiler (2)
16
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 (3)
17
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 )
 LEX
(Character Stream)
Intermediate
Representation
Target machine code
The Structure of a Compiler (4)
18
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 )
 BNF ( Backus-Naur Form )
 GAA ( Grammar Analysis Algorithms )
 LL, LR, SLR, LALR Parsers
 YACC
(Character Stream)
Intermediate
Representation
Target machine code
The Structure of a Compiler (5)
19
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 (6)
20
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 (7)
21
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 (8)
22
Scanner
[Lexical Analyzer]
Parser
[Syntax Analyzer]
Semantic Process
[Semantic analyzer]
Code Generator
[Intermediate Code Generator]
Code Optimizer
Tokens
Parse tree
Abstract Syntax Tree w/ Attributes
Non-optimized Intermediate Code
Optimized Intermediate Code
Code Optimizer
Target machine code
Video on Compilers
1. Introduction to Compiler
2. Application of Phases of Compiler
Questions..
1. Define Compiler?
2. List few applications of Compiler.
3. Explain the phases of compiler?
4. What is mean by token?
Homework..
1. What is parser?
2What is mean by analysis and synthesis.
3. Describe the following example.
area=pi * r * r + 45

Mais conteúdo relacionado

Mais procurados (20)

Token, Pattern and Lexeme
Token, Pattern and LexemeToken, Pattern and Lexeme
Token, Pattern and Lexeme
 
Different phases of a compiler
Different phases of a compilerDifferent phases of a compiler
Different phases of a compiler
 
Compilers Design
Compilers DesignCompilers Design
Compilers Design
 
role of lexical anaysis
role of lexical anaysisrole of lexical anaysis
role of lexical anaysis
 
About Tokens and Lexemes
About Tokens and LexemesAbout Tokens and Lexemes
About Tokens and Lexemes
 
Plc part 2
Plc  part 2Plc  part 2
Plc part 2
 
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
 
Ch1
Ch1Ch1
Ch1
 
Lecture 01 introduction to compiler
Lecture 01 introduction to compilerLecture 01 introduction to compiler
Lecture 01 introduction to compiler
 
Lexical analyzer
Lexical analyzerLexical analyzer
Lexical analyzer
 
Compiler unit 1
Compiler unit 1Compiler unit 1
Compiler unit 1
 
Role-of-lexical-analysis
Role-of-lexical-analysisRole-of-lexical-analysis
Role-of-lexical-analysis
 
Lecture1 introduction compilers
Lecture1 introduction compilersLecture1 introduction compilers
Lecture1 introduction compilers
 
Compiler design and lexical analyser
Compiler design and lexical analyserCompiler design and lexical analyser
Compiler design and lexical analyser
 
Compiler Construction
Compiler ConstructionCompiler Construction
Compiler Construction
 
Chapter#01 cc
Chapter#01 ccChapter#01 cc
Chapter#01 cc
 
Lex
LexLex
Lex
 
Introduction to Compilers | Phases & Structure
Introduction to Compilers | Phases & StructureIntroduction to Compilers | Phases & Structure
Introduction to Compilers | Phases & Structure
 
Type checking in compiler design
Type checking in compiler designType checking in compiler design
Type checking in compiler design
 
Compiler Design Tutorial
Compiler Design Tutorial Compiler Design Tutorial
Compiler Design Tutorial
 

Destaque (6)

SS UI Lecture 1
SS UI Lecture 1SS UI Lecture 1
SS UI Lecture 1
 
Compiler construction
Compiler constructionCompiler construction
Compiler construction
 
Cpcs302 1
Cpcs302  1Cpcs302  1
Cpcs302 1
 
Regular expression (compiler)
Regular expression (compiler)Regular expression (compiler)
Regular expression (compiler)
 
phases of compiler-analysis phase
phases of compiler-analysis phasephases of compiler-analysis phase
phases of compiler-analysis phase
 
System Programming Overview
System Programming OverviewSystem Programming Overview
System Programming Overview
 

Semelhante a Ss ui lecture 2

Semelhante a Ss ui lecture 2 (20)

Assignment1
Assignment1Assignment1
Assignment1
 
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
 
LANGUAGE TRANSLATOR
LANGUAGE TRANSLATORLANGUAGE TRANSLATOR
LANGUAGE TRANSLATOR
 
Lexical analyzer
Lexical analyzerLexical analyzer
Lexical analyzer
 
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
 
First pass of assembler
First pass of assemblerFirst pass of assembler
First pass of assembler
 
Compiler Construction introduction
Compiler Construction introductionCompiler Construction introduction
Compiler Construction introduction
 
Chapter One
Chapter OneChapter One
Chapter One
 
Introduction to Compilers
Introduction to CompilersIntroduction to Compilers
Introduction to Compilers
 
phase of compiler
phase of compilerphase of compiler
phase of compiler
 
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_Lecture1.pdf
Compiler_Lecture1.pdfCompiler_Lecture1.pdf
Compiler_Lecture1.pdf
 
Compier Design_Unit I.ppt
Compier Design_Unit I.pptCompier Design_Unit I.ppt
Compier Design_Unit I.ppt
 
Compier Design_Unit I.ppt
Compier Design_Unit I.pptCompier Design_Unit I.ppt
Compier Design_Unit I.ppt
 
PPT
PPTPPT
PPT
 
Compiler Design.pptx
Compiler Design.pptxCompiler Design.pptx
Compiler Design.pptx
 
Principles of Compiler Design
Principles of Compiler DesignPrinciples of Compiler Design
Principles of Compiler Design
 
Compiler
Compiler Compiler
Compiler
 
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
 

Mais de Avinash Kapse

Mais de Avinash Kapse (8)

Presentation1
Presentation1Presentation1
Presentation1
 
Lecture 2
Lecture 2Lecture 2
Lecture 2
 
Presentation1
Presentation1Presentation1
Presentation1
 
SS UII Lecture 1
SS UII Lecture 1SS UII Lecture 1
SS UII Lecture 1
 
SS UI Lecture 5
SS UI Lecture 5SS UI Lecture 5
SS UI Lecture 5
 
SS UI Lecture 6
SS UI Lecture 6SS UI Lecture 6
SS UI Lecture 6
 
SS UI Lecture 4
SS UI Lecture 4SS UI Lecture 4
SS UI Lecture 4
 
Ss ui lecture 1
Ss ui lecture 1Ss ui lecture 1
Ss ui lecture 1
 

Último

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
 
Introduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxIntroduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxupamatechverse
 
Processing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxProcessing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxpranjaldaimarysona
 
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
Glass Ceramics: Processing and Properties
Glass Ceramics: Processing and PropertiesGlass Ceramics: Processing and Properties
Glass Ceramics: Processing and PropertiesPrabhanshu Chaturvedi
 
MANUFACTURING PROCESS-II UNIT-1 THEORY OF METAL CUTTING
MANUFACTURING PROCESS-II UNIT-1 THEORY OF METAL CUTTINGMANUFACTURING PROCESS-II UNIT-1 THEORY OF METAL CUTTING
MANUFACTURING PROCESS-II UNIT-1 THEORY OF METAL CUTTINGSIVASHANKAR N
 
result management system report for college project
result management system report for college projectresult management system report for college project
result management system report for college projectTonystark477637
 
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINEMANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINESIVASHANKAR N
 
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 Bookingdharasingh5698
 
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 RecordAsst.prof M.Gokilavani
 
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...ranjana rawat
 
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
Introduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxIntroduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxupamatechverse
 
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...roncy bisnoi
 
AKTU Computer Networks notes --- Unit 3.pdf
AKTU Computer Networks notes ---  Unit 3.pdfAKTU Computer Networks notes ---  Unit 3.pdf
AKTU Computer Networks notes --- Unit 3.pdfankushspencer015
 
Extrusion Processes and Their Limitations
Extrusion Processes and Their LimitationsExtrusion Processes and Their Limitations
Extrusion Processes and Their Limitations120cr0395
 
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...ranjana rawat
 

Último (20)

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, ...
 
Introduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxIntroduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptx
 
Processing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxProcessing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptx
 
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
 
Glass Ceramics: Processing and Properties
Glass Ceramics: Processing and PropertiesGlass Ceramics: Processing and Properties
Glass Ceramics: Processing and Properties
 
MANUFACTURING PROCESS-II UNIT-1 THEORY OF METAL CUTTING
MANUFACTURING PROCESS-II UNIT-1 THEORY OF METAL CUTTINGMANUFACTURING PROCESS-II UNIT-1 THEORY OF METAL CUTTING
MANUFACTURING PROCESS-II UNIT-1 THEORY OF METAL CUTTING
 
result management system report for college project
result management system report for college projectresult management system report for college project
result management system report for college project
 
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINEMANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
 
(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
 
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
 
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINEDJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
 
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
 
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
 
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
 
Introduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxIntroduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptx
 
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
 
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
 
AKTU Computer Networks notes --- Unit 3.pdf
AKTU Computer Networks notes ---  Unit 3.pdfAKTU Computer Networks notes ---  Unit 3.pdf
AKTU Computer Networks notes --- Unit 3.pdf
 
Extrusion Processes and Their Limitations
Extrusion Processes and Their LimitationsExtrusion Processes and Their Limitations
Extrusion Processes and Their Limitations
 
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
 

Ss ui lecture 2

  • 1. System Software (5KS03) Unit 1 : Introduction to Compiling Lecture : 2 Phases of a compiler, A S Kapse, Assistant Professor, Department Of Computer Sci. & Engineering Anuradha Engineering College, Chikhli
  • 2. Contents…  Introduction to Compilers  Phases of Compiler
  • 3. Objectives…  Upon completion of this lecture, you will be able  To understand the basics of compiler  To understand Application of compiler  To understand phases of compiler
  • 4. Review…./ Concepts  What do you mean by compiler?  What do you mean by Operating System?  What do you mean by system?
  • 5. The Many Phases of a Compiler Source Program Lexical Analyzer 1 Syntax Analyzer 2 Semantic Analyzer 3 Intermediate Code Generator 4 Code Optimizer 5 Code Generator 6 Target Program Symbol-table Manager Error Handler 1, 2, 3 : Analysis - Our Focus 4, 5, 6 : Synthesis
  • 6. Language-Processing System Source Program Pre-Processor 1 Compiler 2 Assembler 3 Relocatable Machine Code 4 Loader Link/Editor 5 Executable Library, relocatable object files
  • 7.  Three Phases:  Linear / Lexical Analysis:  L-to-r Scan to Identify Tokens token: sequence of chars having a collective meaning  Hierarchical Analysis:  Grouping of Tokens Into Meaningful Collection  Semantic Analysis:  Checking to ensure Correctness of Components The Analysis Task For Compilation
  • 8. Phase 1. Lexical Analysis Easiest Analysis - Identify tokens which are the basic building blocks For Example: All are tokens Blanks, Line breaks, etc. are scanned out Position := initial + rate * 60 ; _______ __ _____ _ ___ _ __ _
  • 9. Phase 2. Hierarchical Analysis aka Parsing or Syntax Analysis For previous example, we would have Parse Tree: identifier identifier expression identifier expression number expression expression expression assignment statement position := + * 60 initial rate Nodes of tree are constructed using a grammar for the language
  • 10. What is a Grammar?  Grammar is a Set of Rules Which Govern the Interdependencies & Structure Among the Tokens statement is an assignment statement, or while statement, or if statement, or ... assignment statement expression is an is an identifier := expression ; (expression), or expression + expression, or expression * expression, or number, or identifier, or ...
  • 11. Why Have We Divided Analysis in This Manner?  Lexical Analysis - Scans Input, Its Linear Actions Are Not Recursive  Identify Only Individual “words” that are the the Tokens of the Language  Recursion Is Required to Identify Structure of an Expression, As Indicated in Parse Tree  Verify that the “words” are Correctly Assembled into “sentences”  What is Third Phase?  Determine Whether the Sentences have One and Only One Unambiguous Interpretation  … and do something about it!  e.g. “John Took Picture of Mary Out on the Patio”
  • 12. Phase 3. Semantic Analysis  Find More Complicated Semantic Errors and Support Code Generation  Parse Tree Is Augmented With Semantic Actions position initial rate := + * 60 Compressed Tree position initial rate := + * inttoreal 60 Conversion Action
  • 13. Phase 3. Semantic Analysis  Most Important Activity in This Phase:  Type Checking - Legality of Operands  Many Different Situations: Real := int + char ; A[int] := A[real] + int ; while char <> int do …. Etc.
  • 14. Supporting Phases/ Activities for Analysis  Symbol Table Creation / Maintenance  Contains Info (storage, type, scope, args) on Each “Meaningful” Token, Typically Identifiers  Data Structure Created / Initialized During Lexical Analysis  Utilized / Updated During Later Analysis & Synthesis  Error Handling  Detection of Different Errors Which Correspond to All Phases  What Kinds of Errors Are Found During the Analysis Phase?  What Happens When an Error Is Found?
  • 15. The Synthesis Task For Compilation  Intermediate Code Generation  Abstract Machine Version of Code - Independent of Architecture  Easy to Produce and Do Final, Machine Dependent Code Generation  Code Optimization  Find More Efficient Ways to Execute Code  Replace Code With More Optimal Statements  2-approaches: High-level Language & “Peephole” Optimization  Final Code Generation  Generate Relocatable Machine Dependent Code
  • 16. The Structure of a Compiler (2) 16 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
  • 17. The Structure of a Compiler (3) 17 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 )  LEX (Character Stream) Intermediate Representation Target machine code
  • 18. The Structure of a Compiler (4) 18 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 )  BNF ( Backus-Naur Form )  GAA ( Grammar Analysis Algorithms )  LL, LR, SLR, LALR Parsers  YACC (Character Stream) Intermediate Representation Target machine code
  • 19. The Structure of a Compiler (5) 19 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
  • 20. The Structure of a Compiler (6) 20 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
  • 21. The Structure of a Compiler (7) 21 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
  • 22. The Structure of a Compiler (8) 22 Scanner [Lexical Analyzer] Parser [Syntax Analyzer] Semantic Process [Semantic analyzer] Code Generator [Intermediate Code Generator] Code Optimizer Tokens Parse tree Abstract Syntax Tree w/ Attributes Non-optimized Intermediate Code Optimized Intermediate Code Code Optimizer Target machine code
  • 23. Video on Compilers 1. Introduction to Compiler 2. Application of Phases of Compiler
  • 24. Questions.. 1. Define Compiler? 2. List few applications of Compiler. 3. Explain the phases of compiler? 4. What is mean by token?
  • 25. Homework.. 1. What is parser? 2What is mean by analysis and synthesis. 3. Describe the following example. area=pi * r * r + 45