SlideShare ist ein Scribd-Unternehmen logo
1 von 40
Introduction to Compiler
Construction (Lecture 1)
Natural Languages
• What are Natural Languages?
• How do you understand the language?
• If you know multiple languages then how
can you recognize each of them?
• How you know which sentence is correct
and which one is incorrect?
Programming Languages
• What are programming languages?
• How do you understand the programming
language?
• If you know multiple programming
languages then how can you recognize each
of them?
• How do you know which syntax is correct
and which one is incorrect?
Compilers and Interpreters
• “Compilation”
– Translation of a program written in a source
language into a semantically equivalent
program written in a target language
– It also reports to its users the presence of errors
in the source program
– C++ uses compiler
Compiler
Error messages
Source
Program
Target
Program
Input
Output4
Compilers and Interpreters
Interpreter
Source
Program
Input
Output
Error messages
• “Interpretation”
– Interpreter is a program that reads an executable
program and produces the results of running that
program. OR
– Instead of producing a target program as a translation,
an interpreter performs the operations implied by the
source program.
– GWBASIC is an example of Interpreter
5
Why study compilers?
• Application of a wide range of theoretical
techniques
– Data Structures
– Theory of Computation
– Algorithms
– Computer Architecture
• Good SW engineering experience
• Better understanding of programming
languages
Features of compilers
• Correctness
– preserve the meaning of the code
• Speed of target code
• Recognize legal and illegal program.
• Speed of compilation
• Good error reporting/handling
• Cooperation with the debugger
• Manage storage of all variables and codes.
• Support for separate compilation
Introduction to Compiler
Construction (Lecture 2)
Classification of Compilers
1. Single Pass Compilers
2. Two Pass Compilers
3. Multipass Compilers
Single Pass Compiler
• Source code directly transforms into
machine code.
– For example Pascal
source
code
target
code
Front EndCompiler
Two Pass Compiler
• Use intermediate representation
– Why?
source
code
target
code
Front End Back End
IR
Front End
Two pass compiler
• intermediate representation (IR)
• front end maps legal code into IR
• back end maps IR onto target machine
• simplify retargeting
• allows multiple front ends
• multiple passes ⇒ better code
12
© Oscar Nierstrasz
Multipass compiler
• analyzes and changes IR
• goal is to reduce runtime
• must preserve values
13
Comparison
• One pass compilers are generally faster than
Multipass Compilers
• Multipass ensures the correctness of small
program rather than the correctness of a
large program (high quality code)
Lecture 3
Front end
• recognize legal code
• report errors
• produce IR
• preliminary storage map
• shape code for the back end
16
Scanner
• Breaks the source code text into small
pieces called tokens.
• It is also known as Lexical Analyzer
Scanner / Lexical Analyser
• map characters to tokens
• character string value for a token is a lexeme
• eliminate white space
x = x + y <id,x> = <id,x> + <id,y>
18
Syntactic Analysis – Parsing
Majid ate the apple
Front end –Analysis– Machine
Independent
• The front end consists of those phases, that
depend primarily on the source language
and are largely independent of the target
machine.
Parser
• recognize context-free syntax
• guide context-sensitive analysis
• construct IR(s)
• produce meaningful error messages
• attempt error correction
21
BACK END
• Synthesis process
• Machine dependent
• The back end includes those portions of the
compiler that depends on the target machine
and generally, these portions do not depend
on the source language
Back end
• translate IR into target machine code
• choose instructions for each IR operation
• decide what to keep in registers at each point
• ensure conformance with system interfaces
23
Compiler Structure
• Front end
– Front end Maps legal code into IR
– Recognize legal/illegal programs
• report/handle errors
– Generate IR
– The process can be automated
• Back end
– Translate IR into target code
• instruction selection
• register allocation
• instruction scheduling
Lecture 4
The Analysis-Synthesis Model
of Compilation
• There are two parts to compilation:
– Analysis determines the operations implied by
the source program which are recorded in a tree
structure
– Synthesis takes the tree structure and translates
the operations therein into the target program
26
ANALYSIS PROCEDURE
• During analysis, the operation implied by
the source program are determined and
recorded in a hierarchical structure called a
tree.
• Often a special type of tree called a Syntax
tree in which each node represents an
operation and the children of a node
represent the arguments of the operation.
Lexical Analyzer
Syntax Analyzer
Semantic Analyzer
character stream position = initial + rate * 60
<id,1> <=> <id,2> <+> <id,3> <*> <60>
=
<id,1>
<id,2>
<id,3>
+
*
60
=
<id,1>
<id,2>
<id,3>
+
*
inttofloat
60
REMEMBER
The front end is responsible for
analysis process while the back
end is responsible for Synthesis
Other Tools that Use the
Analysis-Synthesis Model
• Editors (syntax highlighting)
• Pretty printers (e.g. Doxygen)
• Static checkers (e.g. Lint and Splint)
• Interpreters
• Text formatters (e.g. TeX and LaTeX)
• Silicon compilers (e.g. VHDL)
• Query interpreters/compilers (Databases)
30
Structure Editors
• A structure editor takes as input a sequence of
commands to build a source program.
• The structure editor not only performs the text
creation and modification functions of an ordinary
text editor but it also analyzes the program text,
putting an appropriate hierarchical structure on the
source program.
• Thus the structure editor can perform additional
tasks that are useful in the preparation of
programs.
Structure Editors (cont..)
• For example, it can check that the input is
correctly formed, can supply key words
automatically (e.g. when the user types
while the editor supplies the matching do
and reminds the user that a conditional must
come between them).
Pretty printers
• A pretty printer analyzes a program and
prints it in such a way that the structure of
the program becomes clearly visible.
• For example comments may appear in a
special font, and the statements may appear
with an amount of indentation proportional
to the depth of their nesting in the
hierarchical organization of the statement.
Static Checkers
• A static checker reads a program, analyzes it, and
attempts to discover potential bugs without
running the program.
• A static checker may detect that parts of the source
program can never be executed, or that a certain
variable might be used before being defined.
• In addition, it can catch logical errors such as
trying to use a real variable as a pointer,
employing the type checking techniques.
Interpreters• Instead of producing a target program as a
translation, an interpreter performs the
operations implied by the source program.
• For example, for an assignment statement
an interpreter might build a tree and then
carry out the operations at the nodes as it
“walks” the tree.
:=
<id,1>
<id,2>
<id,3>
+
*
60
position := initial + rate * 60
Interpreters (cont..)• At the root it would discover it had an assignment to
perform, so it would call a routine to evaluate the
expression on the right, and then store the resulting value
in the location associated with the identifier position.
• At the right child of the root, the routine would discover it
had to compute the sum of two expressions
• It would call itself recursively to compute the value of
expression rate * 60
• It would then add that value to the value of the variable
initial
Text Formatters
• A text formatter takes input that is a stream
of characters, most of which is text to be
typeset, but some of which includes
commands to indicate paragraphs, figures or
mathematical structures like subscripts and
superscripts.
Silicon compilers
• A silicon compiler has a source language
that is similar or identical to a conventional
programming language.
• However, the variables of the language
represent, not locations in memory but
logical signals (0 or 1) or groups of signals
in a switching circuit.
Query interpreters
• A query interpreter translates a predicate
containing relational and Boolean operators
into commands to search a database for
records satisfying that predicate.
JIT compilation

Weitere ähnliche Inhalte

Was ist angesagt?

Compiler Design
Compiler DesignCompiler Design
Compiler DesignMir Majid
 
Techniques & applications of Compiler
Techniques & applications of CompilerTechniques & applications of Compiler
Techniques & applications of CompilerPreethi AKNR
 
Intermediate code generation (Compiler Design)
Intermediate code generation (Compiler Design)   Intermediate code generation (Compiler Design)
Intermediate code generation (Compiler Design) Tasif Tanzim
 
Language processing activity
Language processing activityLanguage processing activity
Language processing activityDhruv Sabalpara
 
Compiler Design Basics
Compiler Design BasicsCompiler Design Basics
Compiler Design BasicsAkhil Kaushik
 
COMPILER DESIGN OPTIONS
COMPILER DESIGN OPTIONSCOMPILER DESIGN OPTIONS
COMPILER DESIGN OPTIONSsonalikharade3
 
Error Detection & Recovery
Error Detection & RecoveryError Detection & Recovery
Error Detection & RecoveryAkhil Kaushik
 
The role of the parser and Error recovery strategies ppt in compiler design
The role of the parser and Error recovery strategies ppt in compiler designThe role of the parser and Error recovery strategies ppt in compiler design
The role of the parser and Error recovery strategies ppt in compiler designSadia Akter
 
Types of Statements in Python Programming Language
Types of Statements in Python Programming LanguageTypes of Statements in Python Programming Language
Types of Statements in Python Programming LanguageExplore Skilled
 
Principle source of optimazation
Principle source of optimazationPrinciple source of optimazation
Principle source of optimazationSiva Sathya
 
Fundamentals of Language Processing
Fundamentals of Language ProcessingFundamentals of Language Processing
Fundamentals of Language ProcessingHemant Sharma
 
Threads (operating System)
Threads (operating System)Threads (operating System)
Threads (operating System)Prakhar Maurya
 
Compiler construction tools
Compiler construction toolsCompiler construction tools
Compiler construction toolsAkhil Kaushik
 
Programming Fundamental Presentation
Programming Fundamental PresentationProgramming Fundamental Presentation
Programming Fundamental Presentationfazli khaliq
 
Symbol table in compiler Design
Symbol table in compiler DesignSymbol table in compiler Design
Symbol table in compiler DesignKuppusamy P
 
Compiler design syntax analysis
Compiler design syntax analysisCompiler design syntax analysis
Compiler design syntax analysisRicha Sharma
 

Was ist angesagt? (20)

Compiler Design
Compiler DesignCompiler Design
Compiler Design
 
Techniques & applications of Compiler
Techniques & applications of CompilerTechniques & applications of Compiler
Techniques & applications of Compiler
 
Intermediate code generation (Compiler Design)
Intermediate code generation (Compiler Design)   Intermediate code generation (Compiler Design)
Intermediate code generation (Compiler Design)
 
Compiler design
Compiler designCompiler design
Compiler design
 
Text Editor in System software
Text Editor in System softwareText Editor in System software
Text Editor in System software
 
Assembly Language
Assembly LanguageAssembly Language
Assembly Language
 
1.Role lexical Analyzer
1.Role lexical Analyzer1.Role lexical Analyzer
1.Role lexical Analyzer
 
Language processing activity
Language processing activityLanguage processing activity
Language processing activity
 
Compiler Design Basics
Compiler Design BasicsCompiler Design Basics
Compiler Design Basics
 
COMPILER DESIGN OPTIONS
COMPILER DESIGN OPTIONSCOMPILER DESIGN OPTIONS
COMPILER DESIGN OPTIONS
 
Error Detection & Recovery
Error Detection & RecoveryError Detection & Recovery
Error Detection & Recovery
 
The role of the parser and Error recovery strategies ppt in compiler design
The role of the parser and Error recovery strategies ppt in compiler designThe role of the parser and Error recovery strategies ppt in compiler design
The role of the parser and Error recovery strategies ppt in compiler design
 
Types of Statements in Python Programming Language
Types of Statements in Python Programming LanguageTypes of Statements in Python Programming Language
Types of Statements in Python Programming Language
 
Principle source of optimazation
Principle source of optimazationPrinciple source of optimazation
Principle source of optimazation
 
Fundamentals of Language Processing
Fundamentals of Language ProcessingFundamentals of Language Processing
Fundamentals of Language Processing
 
Threads (operating System)
Threads (operating System)Threads (operating System)
Threads (operating System)
 
Compiler construction tools
Compiler construction toolsCompiler construction tools
Compiler construction tools
 
Programming Fundamental Presentation
Programming Fundamental PresentationProgramming Fundamental Presentation
Programming Fundamental Presentation
 
Symbol table in compiler Design
Symbol table in compiler DesignSymbol table in compiler Design
Symbol table in compiler Design
 
Compiler design syntax analysis
Compiler design syntax analysisCompiler design syntax analysis
Compiler design syntax analysis
 

Andere mochten auch

Andere mochten auch (20)

Compiler Chapter 1
Compiler Chapter 1Compiler Chapter 1
Compiler Chapter 1
 
Compiler Construction
Compiler ConstructionCompiler Construction
Compiler Construction
 
Compiler Construction introduction
Compiler Construction introductionCompiler Construction introduction
Compiler Construction introduction
 
Compiler Construction Course - Introduction
Compiler Construction Course - IntroductionCompiler Construction Course - Introduction
Compiler Construction Course - Introduction
 
Lexical analyzer
Lexical analyzerLexical analyzer
Lexical analyzer
 
Compiler Design(NANTHU NOTES)
Compiler Design(NANTHU NOTES)Compiler Design(NANTHU NOTES)
Compiler Design(NANTHU NOTES)
 
Compilers
CompilersCompilers
Compilers
 
Introduction to Functional Languages
Introduction to Functional LanguagesIntroduction to Functional Languages
Introduction to Functional Languages
 
Passescd
PassescdPassescd
Passescd
 
Classification of Compilers
Classification of CompilersClassification of Compilers
Classification of Compilers
 
Compiler Design Tutorial
Compiler Design Tutorial Compiler Design Tutorial
Compiler Design Tutorial
 
Ch2
Ch2Ch2
Ch2
 
Compiler unit 1
Compiler unit 1Compiler unit 1
Compiler unit 1
 
Compilers
CompilersCompilers
Compilers
 
Assesing speaking skills
Assesing speaking skillsAssesing speaking skills
Assesing speaking skills
 
Introduction to compiler
Introduction to compilerIntroduction to compiler
Introduction to compiler
 
Compiler construction
Compiler constructionCompiler construction
Compiler construction
 
7 compiler lab
7 compiler lab 7 compiler lab
7 compiler lab
 
Lex
LexLex
Lex
 
MTech Seminar Presentation [IIT-Bombay]
MTech Seminar Presentation [IIT-Bombay]MTech Seminar Presentation [IIT-Bombay]
MTech Seminar Presentation [IIT-Bombay]
 

Ähnlich wie Introduction to Compiler Construction

Compiler an overview
Compiler  an overviewCompiler  an overview
Compiler an overviewamudha arul
 
Compiler Design Introduction
Compiler Design Introduction Compiler Design Introduction
Compiler Design Introduction Thapar Institute
 
Compiler Design Basics
Compiler Design BasicsCompiler Design Basics
Compiler Design BasicsAkhil Kaushik
 
4_5802928814682016556.pptx
4_5802928814682016556.pptx4_5802928814682016556.pptx
4_5802928814682016556.pptxAshenafiGirma5
 
Cd ch1 - introduction
Cd   ch1 - introductionCd   ch1 - introduction
Cd ch1 - introductionmengistu23
 
CD - CH1 - Introduction to compiler design.pptx
CD - CH1 - Introduction to compiler design.pptxCD - CH1 - Introduction to compiler design.pptx
CD - CH1 - Introduction to compiler design.pptxZiyadMohammed17
 
COMPILER CONSTRUCTION KU 1.pptx
COMPILER CONSTRUCTION KU 1.pptxCOMPILER CONSTRUCTION KU 1.pptx
COMPILER CONSTRUCTION KU 1.pptxRossy719186
 
Concept of compiler in details
Concept of compiler in detailsConcept of compiler in details
Concept of compiler in detailskazi_aihtesham
 
Introduction to Compilers
Introduction to CompilersIntroduction to Compilers
Introduction to CompilersAkhil Kaushik
 
Compiler Construction
Compiler ConstructionCompiler Construction
Compiler ConstructionAhmed Raza
 
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.pdfDrIsikoIsaac
 
Phases of Compiler.pptx
Phases of Compiler.pptxPhases of Compiler.pptx
Phases of Compiler.pptxssuser3b4934
 
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 MaterialgadisaAdamu
 
PCSG_Computer_Science_Unit_1_Lecture_2.pptx
PCSG_Computer_Science_Unit_1_Lecture_2.pptxPCSG_Computer_Science_Unit_1_Lecture_2.pptx
PCSG_Computer_Science_Unit_1_Lecture_2.pptxAliyahAli19
 
introduction to computer vision and image processing
introduction to computer vision and image processingintroduction to computer vision and image processing
introduction to computer vision and image processingpakboy12
 

Ähnlich wie Introduction to Compiler Construction (20)

Compiler an overview
Compiler  an overviewCompiler  an overview
Compiler an overview
 
Compiler Design Introduction
Compiler Design Introduction Compiler Design Introduction
Compiler Design Introduction
 
Compiler Design Basics
Compiler Design BasicsCompiler Design Basics
Compiler Design Basics
 
4_5802928814682016556.pptx
4_5802928814682016556.pptx4_5802928814682016556.pptx
4_5802928814682016556.pptx
 
Cd ch1 - introduction
Cd   ch1 - introductionCd   ch1 - introduction
Cd ch1 - introduction
 
CD - CH1 - Introduction to compiler design.pptx
CD - CH1 - Introduction to compiler design.pptxCD - CH1 - Introduction to compiler design.pptx
CD - CH1 - Introduction to compiler design.pptx
 
Chapter 1.pptx
Chapter 1.pptxChapter 1.pptx
Chapter 1.pptx
 
COMPILER CONSTRUCTION KU 1.pptx
COMPILER CONSTRUCTION KU 1.pptxCOMPILER CONSTRUCTION KU 1.pptx
COMPILER CONSTRUCTION KU 1.pptx
 
Concept of compiler in details
Concept of compiler in detailsConcept of compiler in details
Concept of compiler in details
 
1._Introduction_.pptx
1._Introduction_.pptx1._Introduction_.pptx
1._Introduction_.pptx
 
Introduction to Compilers
Introduction to CompilersIntroduction to Compilers
Introduction to Compilers
 
Compiler Construction
Compiler ConstructionCompiler Construction
Compiler Construction
 
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 DESIGN PPTS.pptx
COMPILER DESIGN PPTS.pptxCOMPILER DESIGN PPTS.pptx
COMPILER DESIGN PPTS.pptx
 
Phases of Compiler.pptx
Phases of Compiler.pptxPhases of Compiler.pptx
Phases of Compiler.pptx
 
Chap01-Intro.ppt
Chap01-Intro.pptChap01-Intro.ppt
Chap01-Intro.ppt
 
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
 
PCSG_Computer_Science_Unit_1_Lecture_2.pptx
PCSG_Computer_Science_Unit_1_Lecture_2.pptxPCSG_Computer_Science_Unit_1_Lecture_2.pptx
PCSG_Computer_Science_Unit_1_Lecture_2.pptx
 
introduction to computer vision and image processing
introduction to computer vision and image processingintroduction to computer vision and image processing
introduction to computer vision and image processing
 
Unit 1.pptx
Unit 1.pptxUnit 1.pptx
Unit 1.pptx
 

Mehr von Sarmad Ali

Network Engineer Interview Questions with Answers
Network Engineer Interview Questions with Answers Network Engineer Interview Questions with Answers
Network Engineer Interview Questions with Answers Sarmad Ali
 
RDBMS ER2 Relational
RDBMS ER2 RelationalRDBMS ER2 Relational
RDBMS ER2 RelationalSarmad Ali
 
RDBMS Arch & Models
RDBMS Arch & ModelsRDBMS Arch & Models
RDBMS Arch & ModelsSarmad Ali
 
RDBMS ERD Examples
RDBMS ERD ExamplesRDBMS ERD Examples
RDBMS ERD ExamplesSarmad Ali
 
Management Information System-MIS
Management Information System-MISManagement Information System-MIS
Management Information System-MISSarmad Ali
 
Introduction to RDBMS
Introduction to RDBMSIntroduction to RDBMS
Introduction to RDBMSSarmad Ali
 
About Data Base
About Data BaseAbout Data Base
About Data BaseSarmad Ali
 
Management information system-MIS
Management information system-MISManagement information system-MIS
Management information system-MISSarmad Ali
 

Mehr von Sarmad Ali (11)

Network Engineer Interview Questions with Answers
Network Engineer Interview Questions with Answers Network Engineer Interview Questions with Answers
Network Engineer Interview Questions with Answers
 
RDBMS Model
RDBMS ModelRDBMS Model
RDBMS Model
 
RDBMS Algebra
RDBMS AlgebraRDBMS Algebra
RDBMS Algebra
 
RDBMS ERD
RDBMS ERDRDBMS ERD
RDBMS ERD
 
RDBMS ER2 Relational
RDBMS ER2 RelationalRDBMS ER2 Relational
RDBMS ER2 Relational
 
RDBMS Arch & Models
RDBMS Arch & ModelsRDBMS Arch & Models
RDBMS Arch & Models
 
RDBMS ERD Examples
RDBMS ERD ExamplesRDBMS ERD Examples
RDBMS ERD Examples
 
Management Information System-MIS
Management Information System-MISManagement Information System-MIS
Management Information System-MIS
 
Introduction to RDBMS
Introduction to RDBMSIntroduction to RDBMS
Introduction to RDBMS
 
About Data Base
About Data BaseAbout Data Base
About Data Base
 
Management information system-MIS
Management information system-MISManagement information system-MIS
Management information system-MIS
 

Kürzlich hochgeladen

General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...Poonam Aher Patil
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxVishalSingh1417
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSCeline George
 
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxSKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxAmanpreet Kaur
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfagholdier
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17Celine George
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxRamakrishna Reddy Bijjam
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxVishalSingh1417
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfSherif Taha
 
Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Association for Project Management
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxVishalSingh1417
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxheathfieldcps1
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhikauryashika82
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfPoh-Sun Goh
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...ZurliaSoop
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfNirmal Dwivedi
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and ModificationsMJDuyan
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 

Kürzlich hochgeladen (20)

General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptx
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxSKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
Asian American Pacific Islander Month DDSD 2024.pptx
Asian American Pacific Islander Month DDSD 2024.pptxAsian American Pacific Islander Month DDSD 2024.pptx
Asian American Pacific Islander Month DDSD 2024.pptx
 
Spatium Project Simulation student brief
Spatium Project Simulation student briefSpatium Project Simulation student brief
Spatium Project Simulation student brief
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 

Introduction to Compiler Construction

  • 2. Natural Languages • What are Natural Languages? • How do you understand the language? • If you know multiple languages then how can you recognize each of them? • How you know which sentence is correct and which one is incorrect?
  • 3. Programming Languages • What are programming languages? • How do you understand the programming language? • If you know multiple programming languages then how can you recognize each of them? • How do you know which syntax is correct and which one is incorrect?
  • 4. Compilers and Interpreters • “Compilation” – Translation of a program written in a source language into a semantically equivalent program written in a target language – It also reports to its users the presence of errors in the source program – C++ uses compiler Compiler Error messages Source Program Target Program Input Output4
  • 5. Compilers and Interpreters Interpreter Source Program Input Output Error messages • “Interpretation” – Interpreter is a program that reads an executable program and produces the results of running that program. OR – Instead of producing a target program as a translation, an interpreter performs the operations implied by the source program. – GWBASIC is an example of Interpreter 5
  • 6. Why study compilers? • Application of a wide range of theoretical techniques – Data Structures – Theory of Computation – Algorithms – Computer Architecture • Good SW engineering experience • Better understanding of programming languages
  • 7. Features of compilers • Correctness – preserve the meaning of the code • Speed of target code • Recognize legal and illegal program. • Speed of compilation • Good error reporting/handling • Cooperation with the debugger • Manage storage of all variables and codes. • Support for separate compilation
  • 9. Classification of Compilers 1. Single Pass Compilers 2. Two Pass Compilers 3. Multipass Compilers
  • 10. Single Pass Compiler • Source code directly transforms into machine code. – For example Pascal source code target code Front EndCompiler
  • 11. Two Pass Compiler • Use intermediate representation – Why? source code target code Front End Back End IR Front End
  • 12. Two pass compiler • intermediate representation (IR) • front end maps legal code into IR • back end maps IR onto target machine • simplify retargeting • allows multiple front ends • multiple passes ⇒ better code 12
  • 13. © Oscar Nierstrasz Multipass compiler • analyzes and changes IR • goal is to reduce runtime • must preserve values 13
  • 14. Comparison • One pass compilers are generally faster than Multipass Compilers • Multipass ensures the correctness of small program rather than the correctness of a large program (high quality code)
  • 16. Front end • recognize legal code • report errors • produce IR • preliminary storage map • shape code for the back end 16
  • 17. Scanner • Breaks the source code text into small pieces called tokens. • It is also known as Lexical Analyzer
  • 18. Scanner / Lexical Analyser • map characters to tokens • character string value for a token is a lexeme • eliminate white space x = x + y <id,x> = <id,x> + <id,y> 18
  • 19. Syntactic Analysis – Parsing Majid ate the apple
  • 20. Front end –Analysis– Machine Independent • The front end consists of those phases, that depend primarily on the source language and are largely independent of the target machine.
  • 21. Parser • recognize context-free syntax • guide context-sensitive analysis • construct IR(s) • produce meaningful error messages • attempt error correction 21
  • 22. BACK END • Synthesis process • Machine dependent • The back end includes those portions of the compiler that depends on the target machine and generally, these portions do not depend on the source language
  • 23. Back end • translate IR into target machine code • choose instructions for each IR operation • decide what to keep in registers at each point • ensure conformance with system interfaces 23
  • 24. Compiler Structure • Front end – Front end Maps legal code into IR – Recognize legal/illegal programs • report/handle errors – Generate IR – The process can be automated • Back end – Translate IR into target code • instruction selection • register allocation • instruction scheduling
  • 26. The Analysis-Synthesis Model of Compilation • There are two parts to compilation: – Analysis determines the operations implied by the source program which are recorded in a tree structure – Synthesis takes the tree structure and translates the operations therein into the target program 26
  • 27. ANALYSIS PROCEDURE • During analysis, the operation implied by the source program are determined and recorded in a hierarchical structure called a tree. • Often a special type of tree called a Syntax tree in which each node represents an operation and the children of a node represent the arguments of the operation.
  • 28. Lexical Analyzer Syntax Analyzer Semantic Analyzer character stream position = initial + rate * 60 <id,1> <=> <id,2> <+> <id,3> <*> <60> = <id,1> <id,2> <id,3> + * 60 = <id,1> <id,2> <id,3> + * inttofloat 60
  • 29. REMEMBER The front end is responsible for analysis process while the back end is responsible for Synthesis
  • 30. Other Tools that Use the Analysis-Synthesis Model • Editors (syntax highlighting) • Pretty printers (e.g. Doxygen) • Static checkers (e.g. Lint and Splint) • Interpreters • Text formatters (e.g. TeX and LaTeX) • Silicon compilers (e.g. VHDL) • Query interpreters/compilers (Databases) 30
  • 31. Structure Editors • A structure editor takes as input a sequence of commands to build a source program. • The structure editor not only performs the text creation and modification functions of an ordinary text editor but it also analyzes the program text, putting an appropriate hierarchical structure on the source program. • Thus the structure editor can perform additional tasks that are useful in the preparation of programs.
  • 32. Structure Editors (cont..) • For example, it can check that the input is correctly formed, can supply key words automatically (e.g. when the user types while the editor supplies the matching do and reminds the user that a conditional must come between them).
  • 33. Pretty printers • A pretty printer analyzes a program and prints it in such a way that the structure of the program becomes clearly visible. • For example comments may appear in a special font, and the statements may appear with an amount of indentation proportional to the depth of their nesting in the hierarchical organization of the statement.
  • 34. Static Checkers • A static checker reads a program, analyzes it, and attempts to discover potential bugs without running the program. • A static checker may detect that parts of the source program can never be executed, or that a certain variable might be used before being defined. • In addition, it can catch logical errors such as trying to use a real variable as a pointer, employing the type checking techniques.
  • 35. Interpreters• Instead of producing a target program as a translation, an interpreter performs the operations implied by the source program. • For example, for an assignment statement an interpreter might build a tree and then carry out the operations at the nodes as it “walks” the tree. := <id,1> <id,2> <id,3> + * 60 position := initial + rate * 60
  • 36. Interpreters (cont..)• At the root it would discover it had an assignment to perform, so it would call a routine to evaluate the expression on the right, and then store the resulting value in the location associated with the identifier position. • At the right child of the root, the routine would discover it had to compute the sum of two expressions • It would call itself recursively to compute the value of expression rate * 60 • It would then add that value to the value of the variable initial
  • 37. Text Formatters • A text formatter takes input that is a stream of characters, most of which is text to be typeset, but some of which includes commands to indicate paragraphs, figures or mathematical structures like subscripts and superscripts.
  • 38. Silicon compilers • A silicon compiler has a source language that is similar or identical to a conventional programming language. • However, the variables of the language represent, not locations in memory but logical signals (0 or 1) or groups of signals in a switching circuit.
  • 39. Query interpreters • A query interpreter translates a predicate containing relational and Boolean operators into commands to search a database for records satisfying that predicate.

Hinweis der Redaktion

  1. Code improvement - unclear slide
  2. preliminary storage map =&gt; prepare symbol table? shape code for the back end =&gt; same as produce IR?
  3. character string value for a token is a lexeme Typical tokens: id, number, do, end … Key issue is speed