SlideShare a Scribd company logo
Introduction
Why compiler?
Programming problems are easier to solve in high-level languages
Languages closer to the level of the problem domain, e.g.,
SmallTalk: OO programming
JavaScript: Web pages
 Solutions are usually more e�cient (faster, smaller) when written in machine language
Language that reflects to the cycle-by-cycle working of a processor
Compilers are the bridges
Tools to translate programs written in high-level languages to
e�cient executable code
What is a compiler?
"A program that reads a program written in one language and translates it into another
language."
Traditionally, compilers go from high-level languages to low-level
languages.
Traditionally, compilers go from high-level languages to low-level languages.
How to translate?
https://www.slideshare.net/Amansharma1037
https://www.linkedin.com/in/includeaman
Requirement:
In order to translate statements in a language, one needs to understand both
the structure of the language: the way “sentences" are constructed in the
language
the meaning of the language: what each “sentence" stands for.
 Terminology:
Structure ≡ Syntax
Meaning ≡ Semantics
Analysis-Synthesis model of compilation :
Two parts
Analysis
Breaks up the source program into constituents
Synthesis
Constructs the target program
Compilation Steps / Phases
https://www.slideshare.net/Amansharma1037
https://www.linkedin.com/in/includeaman
Compilation Steps/Phases
Lexical Analysis Phase: Generates the “tokens” in the source program
Syntax Analysis Phase: Recognizes “sentences" in the program using the syntax of the
language
Semantic Analysis Phase: Infers information about the program using the semantics of
the language
Intermediate Code Generation Phase: Generates “abstract” code based on the syntactic
structure of the program and the semantic information from Phase 2.
Optimization Phase: Refines the generated code using a series of optimizing
transformations
Final Code Generation Phase: Translates the abstract intermediate code into specific
machine instructions.
Lexical Analysis
Convert the stream of characters representing input program into a sequence of tokens
Tokens are the “words" of the programming language
https://www.slideshare.net/Amansharma1037
https://www.linkedin.com/in/includeaman
Lexeme
The characters comprising a token
For Example,
the sequence of characters “static int" is recognized as two tokens, representing
the two words
“static" and “int"
The sequence of characters “*x++" is recognized as three tokens, representing
“*", “x" and “++“
Removes the white spaces
Removes the comments
Lexical Analysis
Input: result = a + b * 10
Tokens:
Syntax Analysis
Uncover the structure of a sentence in the program from a stream of tokens.
For instance, the phrase “x = +y", which is recognized as four tokens, representing “x",
“=“ and “+" and “y", has the
structure =(x,+(y)), i.e., an assignment expression, that operates on “x" and the
expression “+(y)".
Build a tree called a parse tree that reflects the structure of the input sentence.
Syntax Analysis: Grammars
Expression grammar
Exp ::=Exp ‘+’ Exp | Exp ‘*’ Exp | ID | NUMBER
https://www.slideshare.net/Amansharma1037
https://www.linkedin.com/in/includeaman
Assign ::= ID ‘=‘ Exp
Syntax Tree
Input: result = a + b * 10
Semantic Analysis
Concerned with the semantic (meaning) of the program
Performs type checking
Operator operand compitability
Intermediate Code Generation
Translate each hierarchical structure decorated as tree into intermediate code
A program translated for an abstract machine
Properties of intermediate codes
Should be easy to generate
Should be easy to translate
Intermediate code hides many machine-level details, but has instruction-level mapping
to many assembly languages
Main motivation: portability
One commonly used form is “Three-address Code”
Code Optimization
Apply a series of transformations to improve the time and space e�ciency of the
generated code.
Peephole optimizations: generate new instructions by combining/expanding on a small
number of consecutive instructions.
https://www.slideshare.net/Amansharma1037
https://www.linkedin.com/in/includeaman
Global optimizations: reorder, remove or add instructions to change the structure of
generated code
Consumes a significant fraction of the compilation time
Optimization capability varies widely
Simple optimization techniques can be very valuable
Code Generation
Map instructions in the intermediate code to specific machine instructions.
Memory management, register allocation, instruction selection, instruction scheduling,
...
Generates su�cient information to enable symbolic debugging.
Symbol Table
Records the identifiers used in the source program
Collects various associated information as attributes
Variables: type, scope, storage allocation
Procedure: number and types of arguments method of argument passing
It’s a data structure with collection of records
Di�erent fields are collected and used at di�erent phases of compilation
Error Detection, Recovery and Reporting
Each phase can encounter error
Specific types of error can be detected by specific phases
Lexical Error: int abc, 1num;
Syntax Error: total = capital + rate year;
Semantic Error: value = myarray [realIndex];
Should be able to proceed and process the rest of the program after an error detected
Should be able to link the error with the source program
https://www.slideshare.net/Amansharma1037
https://www.linkedin.com/in/includeaman
Translation of a statement
https://www.slideshare.net/Amansharma1037
https://www.linkedin.com/in/includeaman
https://www.slideshare.net/Amansharma1037
https://www.linkedin.com/in/includeaman
https://www.slideshare.net/Amansharma1037
https://www.linkedin.com/in/includeaman
https://www.slideshare.net/Amansharma1037
https://www.linkedin.com/in/includeaman
Syntax Analyzer versus Lexical Analyzer
Both of them do the similiar thing ;
But the lexical analyzer deals with simple non-recursive constructs of the language.
The syntax analyzer deals with recursive constructs of the language.
The lexical analyzer simplifies the job of the syntax analyzer.
The lexical analyzer recognizes the smallest meaningful units (tokens) in a source
program.
The syntax analyzer works on the smallest meaningful units (tokens) in a source program
to recognize meaningful structures in our programming language.
Cousins of the Compiler
Preprocessor
Macro preprocessing : Define and use shorthand for longer constructs
File inclusion :Include header files
“Rational” Preprocessors :Augment older languages with modern flow-of-control or
data-structures
Language Extension:Add capabilities to a language
Equel: query language embedded in C
Assemblers
https://www.slideshare.net/Amansharma1037
https://www.linkedin.com/in/includeaman
Two-Pass Assembly
Simplest form of assembler
First pass
All the identifiers are stored in a symbol table
Storage is allocated
Second pass
Translates each operand code in the machine language
https://www.slideshare.net/Amansharma1037
https://www.linkedin.com/in/includeaman
Loaders and Link-Editors
Loader Converts the relocatable machine code into absolute machine code
Map the relocatable address
Place altered instructions and data in memory
Linker Makes a single program from several files of relocatable machine code
Several files of relocatable codes
Library files
Grouping of Phases
Front End and Back End with Front end consisting of phases that depend iupon source
language and are independent of target language.
Passes : Several phases of compilers with similiar function are grouped in Passes.
often Passes generate an explicit output file
In each pass whole input file is processed.
Issues Driving Compiler Design
Correctness
Speed (runtime and compile time)
https://www.slideshare.net/Amansharma1037
https://www.linkedin.com/in/includeaman
Degrees of optimization
Multiple passes
Space
Feedback to user
Debugging
Other Applications
In addition to the development of a compiler, the techniques used in compiler design
can be applicable to many problems in computer science.
Techniques used in a lexical analyzer can be used in text editors, information retrieval
system, and pattern recognition programs.
Techniques used in a parser can be used in a query processing system such as SQL.
Many software having a complex front-end may need techniques used in compiler
design.
A symbolic equation solver which takes an equation as input.That program should parse
the given input equation.
Most of the techniques used in compiler design can be used in Natural Language
Processing (NLP) systems.
https://www.slideshare.net/Amansharma1037
https://www.linkedin.com/in/includeaman

More Related Content

What's hot

Introduction to computer programming
Introduction to computer programmingIntroduction to computer programming
Introduction to computer programming
Noel Malle
 
Compiler Construction introduction
Compiler Construction introductionCompiler Construction introduction
Compiler Construction introduction
Rana Ehtisham Ul Haq
 
Common language runtime clr
Common language runtime clrCommon language runtime clr
Common language runtime clr
SanSan149
 
Compiler Design
Compiler DesignCompiler Design
Compiler DesignMir Majid
 
System Programming Overview
System Programming OverviewSystem Programming Overview
System Programming Overview
Dattatray Gandhmal
 
loaders and linkers
 loaders and linkers loaders and linkers
loaders and linkers
Temesgen Molla
 
Swift Introduction
Swift IntroductionSwift Introduction
Swift Introduction
Savvycom Savvycom
 
CSharp Presentation
CSharp PresentationCSharp Presentation
CSharp Presentation
Vishwa Mohan
 
Comments in C Programming
Comments in C ProgrammingComments in C Programming
Comments in C Programming
programming9
 
Language processing activity
Language processing activityLanguage processing activity
Language processing activity
Dhruv Sabalpara
 
[Android] Web services
[Android] Web services[Android] Web services
[Android] Web services
Nikmesoft Ltd
 
Unit 4 sp macro
Unit 4 sp macroUnit 4 sp macro
Unit 4 sp macro
Deepmala Sharma
 
Fundamentals of Language Processing
Fundamentals of Language ProcessingFundamentals of Language Processing
Fundamentals of Language Processing
Hemant Sharma
 
Google Firebase presentation - English
Google Firebase presentation - EnglishGoogle Firebase presentation - English
Google Firebase presentation - English
Alexandros Tsichouridis
 
COMMAND LINE ARGUMENT IN C++
COMMAND LINE ARGUMENT IN C++COMMAND LINE ARGUMENT IN C++
COMMAND LINE ARGUMENT IN C++
Harshita426026
 
Evolution of Computer Languages
Evolution of Computer LanguagesEvolution of Computer Languages
Evolution of Computer Languages
Electro Computer Warehouse
 
Flutter
FlutterFlutter
Flutter
FlutterFlutter
Flutter
Ankit Kumar
 

What's hot (20)

Introduction to computer programming
Introduction to computer programmingIntroduction to computer programming
Introduction to computer programming
 
Compiler Construction introduction
Compiler Construction introductionCompiler Construction introduction
Compiler Construction introduction
 
Common language runtime clr
Common language runtime clrCommon language runtime clr
Common language runtime clr
 
Compiler Design
Compiler DesignCompiler Design
Compiler Design
 
System Programming Overview
System Programming OverviewSystem Programming Overview
System Programming Overview
 
loaders and linkers
 loaders and linkers loaders and linkers
loaders and linkers
 
Swift Introduction
Swift IntroductionSwift Introduction
Swift Introduction
 
C language unit-1
C language unit-1C language unit-1
C language unit-1
 
CSharp Presentation
CSharp PresentationCSharp Presentation
CSharp Presentation
 
Comments in C Programming
Comments in C ProgrammingComments in C Programming
Comments in C Programming
 
Language processing activity
Language processing activityLanguage processing activity
Language processing activity
 
[Android] Web services
[Android] Web services[Android] Web services
[Android] Web services
 
Unit 4 sp macro
Unit 4 sp macroUnit 4 sp macro
Unit 4 sp macro
 
Fundamentals of Language Processing
Fundamentals of Language ProcessingFundamentals of Language Processing
Fundamentals of Language Processing
 
Google Firebase presentation - English
Google Firebase presentation - EnglishGoogle Firebase presentation - English
Google Firebase presentation - English
 
COMMAND LINE ARGUMENT IN C++
COMMAND LINE ARGUMENT IN C++COMMAND LINE ARGUMENT IN C++
COMMAND LINE ARGUMENT IN C++
 
Evolution of Computer Languages
Evolution of Computer LanguagesEvolution of Computer Languages
Evolution of Computer Languages
 
Flutter
FlutterFlutter
Flutter
 
Flutter
FlutterFlutter
Flutter
 
Computer
ComputerComputer
Computer
 

Similar to Compiler design Introduction

Compiler_Lecture1.pdf
Compiler_Lecture1.pdfCompiler_Lecture1.pdf
Compiler_Lecture1.pdf
AkarTaher
 
Chapter One
Chapter OneChapter One
Chapter Onebolovv
 
Lecture 01 introduction to compiler
Lecture 01 introduction to compilerLecture 01 introduction to compiler
Lecture 01 introduction to compiler
Iffat Anjum
 
Language translators
Language translatorsLanguage translators
Language translatorsAditya Sharat
 
Chapter#01 cc
Chapter#01 ccChapter#01 cc
Chapter#01 cc
abdulbaki3
 
Prof. Chethan Raj C, BE, M.Tech (Ph.D) Dept. of CSE. System Software & Operat...
Prof. Chethan Raj C, BE, M.Tech (Ph.D) Dept. of CSE. System Software & Operat...Prof. Chethan Raj C, BE, M.Tech (Ph.D) Dept. of CSE. System Software & Operat...
Prof. Chethan Raj C, BE, M.Tech (Ph.D) Dept. of CSE. System Software & Operat...
Prof Chethan Raj C
 
compiler construction tool in computer science .
compiler construction tool in computer science .compiler construction tool in computer science .
compiler construction tool in computer science .
RanitHalder
 
2 Programming Language.pdf
2 Programming Language.pdf2 Programming Language.pdf
2 Programming Language.pdf
KINGZzofYouTube
 
Lecture 1 introduction to language processors
Lecture 1  introduction to language processorsLecture 1  introduction to language processors
Lecture 1 introduction to language processors
Rebaz Najeeb
 
SOFTWARE TOOL FOR TRANSLATING PSEUDOCODE TO A PROGRAMMING LANGUAGE
SOFTWARE TOOL FOR TRANSLATING PSEUDOCODE TO A PROGRAMMING LANGUAGESOFTWARE TOOL FOR TRANSLATING PSEUDOCODE TO A PROGRAMMING LANGUAGE
SOFTWARE TOOL FOR TRANSLATING PSEUDOCODE TO A PROGRAMMING LANGUAGE
IJCI JOURNAL
 
SOFTWARE TOOL FOR TRANSLATING PSEUDOCODE TO A PROGRAMMING LANGUAGE
SOFTWARE TOOL FOR TRANSLATING PSEUDOCODE TO A PROGRAMMING LANGUAGESOFTWARE TOOL FOR TRANSLATING PSEUDOCODE TO A PROGRAMMING LANGUAGE
SOFTWARE TOOL FOR TRANSLATING PSEUDOCODE TO A PROGRAMMING LANGUAGE
IJCI JOURNAL
 
Cpcs302 1
Cpcs302  1Cpcs302  1
Cpcs302 1
guest5de1a5
 
Plc part 2
Plc  part 2Plc  part 2
Plc part 2
Taymoor Nazmy
 
PSEUDOCODE TO SOURCE PROGRAMMING LANGUAGE TRANSLATOR
PSEUDOCODE TO SOURCE PROGRAMMING LANGUAGE TRANSLATORPSEUDOCODE TO SOURCE PROGRAMMING LANGUAGE TRANSLATOR
PSEUDOCODE TO SOURCE PROGRAMMING LANGUAGE TRANSLATOR
ijistjournal
 
Chapter1pdf__2021_11_23_10_53_20.pdf
Chapter1pdf__2021_11_23_10_53_20.pdfChapter1pdf__2021_11_23_10_53_20.pdf
Chapter1pdf__2021_11_23_10_53_20.pdf
DrIsikoIsaac
 
My cool new Slideshow!
My cool new Slideshow!My cool new Slideshow!
My cool new Slideshow!manishamorya
 
01 Database Management (re-uploaded)
01 Database Management (re-uploaded)01 Database Management (re-uploaded)
01 Database Management (re-uploaded)
bluejayjunior
 

Similar to Compiler design Introduction (20)

Compiler_Lecture1.pdf
Compiler_Lecture1.pdfCompiler_Lecture1.pdf
Compiler_Lecture1.pdf
 
Chapter One
Chapter OneChapter One
Chapter One
 
Lecture 01 introduction to compiler
Lecture 01 introduction to compilerLecture 01 introduction to compiler
Lecture 01 introduction to compiler
 
Language translators
Language translatorsLanguage translators
Language translators
 
Chapter#01 cc
Chapter#01 ccChapter#01 cc
Chapter#01 cc
 
How a Compiler Works ?
How a Compiler Works ?How a Compiler Works ?
How a Compiler Works ?
 
Compiler Design Material
Compiler Design MaterialCompiler Design Material
Compiler Design Material
 
Prof. Chethan Raj C, BE, M.Tech (Ph.D) Dept. of CSE. System Software & Operat...
Prof. Chethan Raj C, BE, M.Tech (Ph.D) Dept. of CSE. System Software & Operat...Prof. Chethan Raj C, BE, M.Tech (Ph.D) Dept. of CSE. System Software & Operat...
Prof. Chethan Raj C, BE, M.Tech (Ph.D) Dept. of CSE. System Software & Operat...
 
3.2
3.23.2
3.2
 
compiler construction tool in computer science .
compiler construction tool in computer science .compiler construction tool in computer science .
compiler construction tool in computer science .
 
2 Programming Language.pdf
2 Programming Language.pdf2 Programming Language.pdf
2 Programming Language.pdf
 
Lecture 1 introduction to language processors
Lecture 1  introduction to language processorsLecture 1  introduction to language processors
Lecture 1 introduction to language processors
 
SOFTWARE TOOL FOR TRANSLATING PSEUDOCODE TO A PROGRAMMING LANGUAGE
SOFTWARE TOOL FOR TRANSLATING PSEUDOCODE TO A PROGRAMMING LANGUAGESOFTWARE TOOL FOR TRANSLATING PSEUDOCODE TO A PROGRAMMING LANGUAGE
SOFTWARE TOOL FOR TRANSLATING PSEUDOCODE TO A PROGRAMMING LANGUAGE
 
SOFTWARE TOOL FOR TRANSLATING PSEUDOCODE TO A PROGRAMMING LANGUAGE
SOFTWARE TOOL FOR TRANSLATING PSEUDOCODE TO A PROGRAMMING LANGUAGESOFTWARE TOOL FOR TRANSLATING PSEUDOCODE TO A PROGRAMMING LANGUAGE
SOFTWARE TOOL FOR TRANSLATING PSEUDOCODE TO A PROGRAMMING LANGUAGE
 
Cpcs302 1
Cpcs302  1Cpcs302  1
Cpcs302 1
 
Plc part 2
Plc  part 2Plc  part 2
Plc part 2
 
PSEUDOCODE TO SOURCE PROGRAMMING LANGUAGE TRANSLATOR
PSEUDOCODE TO SOURCE PROGRAMMING LANGUAGE TRANSLATORPSEUDOCODE TO SOURCE PROGRAMMING LANGUAGE TRANSLATOR
PSEUDOCODE TO SOURCE PROGRAMMING LANGUAGE TRANSLATOR
 
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
 
My cool new Slideshow!
My cool new Slideshow!My cool new Slideshow!
My cool new Slideshow!
 
01 Database Management (re-uploaded)
01 Database Management (re-uploaded)01 Database Management (re-uploaded)
01 Database Management (re-uploaded)
 

More from Aman Sharma

Information architecture unit i
Information architecture unit iInformation architecture unit i
Information architecture unit i
Aman Sharma
 
Lexical Analysis - Compiler design
Lexical Analysis - Compiler design Lexical Analysis - Compiler design
Lexical Analysis - Compiler design
Aman Sharma
 
Role of supoort Institutions & Management of Small Business UNIT IV
 Role of supoort Institutions & Management of Small Business UNIT IV Role of supoort Institutions & Management of Small Business UNIT IV
Role of supoort Institutions & Management of Small Business UNIT IV
Aman Sharma
 
Small Enterprises and Enterprise Launching Formalitites UNIT III
Small Enterprises and Enterprise Launching Formalitites UNIT IIISmall Enterprises and Enterprise Launching Formalitites UNIT III
Small Enterprises and Enterprise Launching Formalitites UNIT III
Aman Sharma
 
Opportunity Identification and Product selection UNIT II
Opportunity Identification  and Product selection UNIT IIOpportunity Identification  and Product selection UNIT II
Opportunity Identification and Product selection UNIT II
Aman Sharma
 
Entrepreneurship & Entreprenurs Unit I
Entrepreneurship & Entreprenurs Unit IEntrepreneurship & Entreprenurs Unit I
Entrepreneurship & Entreprenurs Unit I
Aman Sharma
 

More from Aman Sharma (6)

Information architecture unit i
Information architecture unit iInformation architecture unit i
Information architecture unit i
 
Lexical Analysis - Compiler design
Lexical Analysis - Compiler design Lexical Analysis - Compiler design
Lexical Analysis - Compiler design
 
Role of supoort Institutions & Management of Small Business UNIT IV
 Role of supoort Institutions & Management of Small Business UNIT IV Role of supoort Institutions & Management of Small Business UNIT IV
Role of supoort Institutions & Management of Small Business UNIT IV
 
Small Enterprises and Enterprise Launching Formalitites UNIT III
Small Enterprises and Enterprise Launching Formalitites UNIT IIISmall Enterprises and Enterprise Launching Formalitites UNIT III
Small Enterprises and Enterprise Launching Formalitites UNIT III
 
Opportunity Identification and Product selection UNIT II
Opportunity Identification  and Product selection UNIT IIOpportunity Identification  and Product selection UNIT II
Opportunity Identification and Product selection UNIT II
 
Entrepreneurship & Entreprenurs Unit I
Entrepreneurship & Entreprenurs Unit IEntrepreneurship & Entreprenurs Unit I
Entrepreneurship & Entreprenurs Unit I
 

Recently uploaded

H.Seo, ICLR 2024, MLILAB, KAIST AI.pdf
H.Seo,  ICLR 2024, MLILAB,  KAIST AI.pdfH.Seo,  ICLR 2024, MLILAB,  KAIST AI.pdf
H.Seo, ICLR 2024, MLILAB, KAIST AI.pdf
MLILAB
 
Student information management system project report ii.pdf
Student information management system project report ii.pdfStudent information management system project report ii.pdf
Student information management system project report ii.pdf
Kamal Acharya
 
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
ydteq
 
Water Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation and Control Monthly - May 2024.pdfWater Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation & Control
 
CME397 Surface Engineering- Professional Elective
CME397 Surface Engineering- Professional ElectiveCME397 Surface Engineering- Professional Elective
CME397 Surface Engineering- Professional Elective
karthi keyan
 
ML for identifying fraud using open blockchain data.pptx
ML for identifying fraud using open blockchain data.pptxML for identifying fraud using open blockchain data.pptx
ML for identifying fraud using open blockchain data.pptx
Vijay Dialani, PhD
 
power quality voltage fluctuation UNIT - I.pptx
power quality voltage fluctuation UNIT - I.pptxpower quality voltage fluctuation UNIT - I.pptx
power quality voltage fluctuation UNIT - I.pptx
ViniHema
 
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Dr.Costas Sachpazis
 
ethical hacking-mobile hacking methods.ppt
ethical hacking-mobile hacking methods.pptethical hacking-mobile hacking methods.ppt
ethical hacking-mobile hacking methods.ppt
Jayaprasanna4
 
Cosmetic shop management system project report.pdf
Cosmetic shop management system project report.pdfCosmetic shop management system project report.pdf
Cosmetic shop management system project report.pdf
Kamal Acharya
 
block diagram and signal flow graph representation
block diagram and signal flow graph representationblock diagram and signal flow graph representation
block diagram and signal flow graph representation
Divya Somashekar
 
Gen AI Study Jams _ For the GDSC Leads in India.pdf
Gen AI Study Jams _ For the GDSC Leads in India.pdfGen AI Study Jams _ For the GDSC Leads in India.pdf
Gen AI Study Jams _ For the GDSC Leads in India.pdf
gdsczhcet
 
ethical hacking in wireless-hacking1.ppt
ethical hacking in wireless-hacking1.pptethical hacking in wireless-hacking1.ppt
ethical hacking in wireless-hacking1.ppt
Jayaprasanna4
 
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
zwunae
 
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdfAKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
SamSarthak3
 
ASME IX(9) 2007 Full Version .pdf
ASME IX(9)  2007 Full Version       .pdfASME IX(9)  2007 Full Version       .pdf
ASME IX(9) 2007 Full Version .pdf
AhmedHussein950959
 
The Benefits and Techniques of Trenchless Pipe Repair.pdf
The Benefits and Techniques of Trenchless Pipe Repair.pdfThe Benefits and Techniques of Trenchless Pipe Repair.pdf
The Benefits and Techniques of Trenchless Pipe Repair.pdf
Pipe Restoration Solutions
 
AP LAB PPT.pdf ap lab ppt no title specific
AP LAB PPT.pdf ap lab ppt no title specificAP LAB PPT.pdf ap lab ppt no title specific
AP LAB PPT.pdf ap lab ppt no title specific
BrazilAccount1
 
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
thanhdowork
 
Immunizing Image Classifiers Against Localized Adversary Attacks
Immunizing Image Classifiers Against Localized Adversary AttacksImmunizing Image Classifiers Against Localized Adversary Attacks
Immunizing Image Classifiers Against Localized Adversary Attacks
gerogepatton
 

Recently uploaded (20)

H.Seo, ICLR 2024, MLILAB, KAIST AI.pdf
H.Seo,  ICLR 2024, MLILAB,  KAIST AI.pdfH.Seo,  ICLR 2024, MLILAB,  KAIST AI.pdf
H.Seo, ICLR 2024, MLILAB, KAIST AI.pdf
 
Student information management system project report ii.pdf
Student information management system project report ii.pdfStudent information management system project report ii.pdf
Student information management system project report ii.pdf
 
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
 
Water Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation and Control Monthly - May 2024.pdfWater Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation and Control Monthly - May 2024.pdf
 
CME397 Surface Engineering- Professional Elective
CME397 Surface Engineering- Professional ElectiveCME397 Surface Engineering- Professional Elective
CME397 Surface Engineering- Professional Elective
 
ML for identifying fraud using open blockchain data.pptx
ML for identifying fraud using open blockchain data.pptxML for identifying fraud using open blockchain data.pptx
ML for identifying fraud using open blockchain data.pptx
 
power quality voltage fluctuation UNIT - I.pptx
power quality voltage fluctuation UNIT - I.pptxpower quality voltage fluctuation UNIT - I.pptx
power quality voltage fluctuation UNIT - I.pptx
 
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
 
ethical hacking-mobile hacking methods.ppt
ethical hacking-mobile hacking methods.pptethical hacking-mobile hacking methods.ppt
ethical hacking-mobile hacking methods.ppt
 
Cosmetic shop management system project report.pdf
Cosmetic shop management system project report.pdfCosmetic shop management system project report.pdf
Cosmetic shop management system project report.pdf
 
block diagram and signal flow graph representation
block diagram and signal flow graph representationblock diagram and signal flow graph representation
block diagram and signal flow graph representation
 
Gen AI Study Jams _ For the GDSC Leads in India.pdf
Gen AI Study Jams _ For the GDSC Leads in India.pdfGen AI Study Jams _ For the GDSC Leads in India.pdf
Gen AI Study Jams _ For the GDSC Leads in India.pdf
 
ethical hacking in wireless-hacking1.ppt
ethical hacking in wireless-hacking1.pptethical hacking in wireless-hacking1.ppt
ethical hacking in wireless-hacking1.ppt
 
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
 
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdfAKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
 
ASME IX(9) 2007 Full Version .pdf
ASME IX(9)  2007 Full Version       .pdfASME IX(9)  2007 Full Version       .pdf
ASME IX(9) 2007 Full Version .pdf
 
The Benefits and Techniques of Trenchless Pipe Repair.pdf
The Benefits and Techniques of Trenchless Pipe Repair.pdfThe Benefits and Techniques of Trenchless Pipe Repair.pdf
The Benefits and Techniques of Trenchless Pipe Repair.pdf
 
AP LAB PPT.pdf ap lab ppt no title specific
AP LAB PPT.pdf ap lab ppt no title specificAP LAB PPT.pdf ap lab ppt no title specific
AP LAB PPT.pdf ap lab ppt no title specific
 
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
 
Immunizing Image Classifiers Against Localized Adversary Attacks
Immunizing Image Classifiers Against Localized Adversary AttacksImmunizing Image Classifiers Against Localized Adversary Attacks
Immunizing Image Classifiers Against Localized Adversary Attacks
 

Compiler design Introduction

  • 1. Introduction Why compiler? Programming problems are easier to solve in high-level languages Languages closer to the level of the problem domain, e.g., SmallTalk: OO programming JavaScript: Web pages  Solutions are usually more e�cient (faster, smaller) when written in machine language Language that reflects to the cycle-by-cycle working of a processor Compilers are the bridges Tools to translate programs written in high-level languages to e�cient executable code What is a compiler? "A program that reads a program written in one language and translates it into another language." Traditionally, compilers go from high-level languages to low-level languages. Traditionally, compilers go from high-level languages to low-level languages. How to translate? https://www.slideshare.net/Amansharma1037 https://www.linkedin.com/in/includeaman
  • 2. Requirement: In order to translate statements in a language, one needs to understand both the structure of the language: the way “sentences" are constructed in the language the meaning of the language: what each “sentence" stands for.  Terminology: Structure ≡ Syntax Meaning ≡ Semantics Analysis-Synthesis model of compilation : Two parts Analysis Breaks up the source program into constituents Synthesis Constructs the target program Compilation Steps / Phases https://www.slideshare.net/Amansharma1037 https://www.linkedin.com/in/includeaman
  • 3. Compilation Steps/Phases Lexical Analysis Phase: Generates the “tokens” in the source program Syntax Analysis Phase: Recognizes “sentences" in the program using the syntax of the language Semantic Analysis Phase: Infers information about the program using the semantics of the language Intermediate Code Generation Phase: Generates “abstract” code based on the syntactic structure of the program and the semantic information from Phase 2. Optimization Phase: Refines the generated code using a series of optimizing transformations Final Code Generation Phase: Translates the abstract intermediate code into specific machine instructions. Lexical Analysis Convert the stream of characters representing input program into a sequence of tokens Tokens are the “words" of the programming language https://www.slideshare.net/Amansharma1037 https://www.linkedin.com/in/includeaman
  • 4. Lexeme The characters comprising a token For Example, the sequence of characters “static int" is recognized as two tokens, representing the two words “static" and “int" The sequence of characters “*x++" is recognized as three tokens, representing “*", “x" and “++“ Removes the white spaces Removes the comments Lexical Analysis Input: result = a + b * 10 Tokens: Syntax Analysis Uncover the structure of a sentence in the program from a stream of tokens. For instance, the phrase “x = +y", which is recognized as four tokens, representing “x", “=“ and “+" and “y", has the structure =(x,+(y)), i.e., an assignment expression, that operates on “x" and the expression “+(y)". Build a tree called a parse tree that reflects the structure of the input sentence. Syntax Analysis: Grammars Expression grammar Exp ::=Exp ‘+’ Exp | Exp ‘*’ Exp | ID | NUMBER https://www.slideshare.net/Amansharma1037 https://www.linkedin.com/in/includeaman
  • 5. Assign ::= ID ‘=‘ Exp Syntax Tree Input: result = a + b * 10 Semantic Analysis Concerned with the semantic (meaning) of the program Performs type checking Operator operand compitability Intermediate Code Generation Translate each hierarchical structure decorated as tree into intermediate code A program translated for an abstract machine Properties of intermediate codes Should be easy to generate Should be easy to translate Intermediate code hides many machine-level details, but has instruction-level mapping to many assembly languages Main motivation: portability One commonly used form is “Three-address Code” Code Optimization Apply a series of transformations to improve the time and space e�ciency of the generated code. Peephole optimizations: generate new instructions by combining/expanding on a small number of consecutive instructions. https://www.slideshare.net/Amansharma1037 https://www.linkedin.com/in/includeaman
  • 6. Global optimizations: reorder, remove or add instructions to change the structure of generated code Consumes a significant fraction of the compilation time Optimization capability varies widely Simple optimization techniques can be very valuable Code Generation Map instructions in the intermediate code to specific machine instructions. Memory management, register allocation, instruction selection, instruction scheduling, ... Generates su�cient information to enable symbolic debugging. Symbol Table Records the identifiers used in the source program Collects various associated information as attributes Variables: type, scope, storage allocation Procedure: number and types of arguments method of argument passing It’s a data structure with collection of records Di�erent fields are collected and used at di�erent phases of compilation Error Detection, Recovery and Reporting Each phase can encounter error Specific types of error can be detected by specific phases Lexical Error: int abc, 1num; Syntax Error: total = capital + rate year; Semantic Error: value = myarray [realIndex]; Should be able to proceed and process the rest of the program after an error detected Should be able to link the error with the source program https://www.slideshare.net/Amansharma1037 https://www.linkedin.com/in/includeaman
  • 7. Translation of a statement https://www.slideshare.net/Amansharma1037 https://www.linkedin.com/in/includeaman
  • 11. Syntax Analyzer versus Lexical Analyzer Both of them do the similiar thing ; But the lexical analyzer deals with simple non-recursive constructs of the language. The syntax analyzer deals with recursive constructs of the language. The lexical analyzer simplifies the job of the syntax analyzer. The lexical analyzer recognizes the smallest meaningful units (tokens) in a source program. The syntax analyzer works on the smallest meaningful units (tokens) in a source program to recognize meaningful structures in our programming language. Cousins of the Compiler Preprocessor Macro preprocessing : Define and use shorthand for longer constructs File inclusion :Include header files “Rational” Preprocessors :Augment older languages with modern flow-of-control or data-structures Language Extension:Add capabilities to a language Equel: query language embedded in C Assemblers https://www.slideshare.net/Amansharma1037 https://www.linkedin.com/in/includeaman
  • 12. Two-Pass Assembly Simplest form of assembler First pass All the identifiers are stored in a symbol table Storage is allocated Second pass Translates each operand code in the machine language https://www.slideshare.net/Amansharma1037 https://www.linkedin.com/in/includeaman
  • 13. Loaders and Link-Editors Loader Converts the relocatable machine code into absolute machine code Map the relocatable address Place altered instructions and data in memory Linker Makes a single program from several files of relocatable machine code Several files of relocatable codes Library files Grouping of Phases Front End and Back End with Front end consisting of phases that depend iupon source language and are independent of target language. Passes : Several phases of compilers with similiar function are grouped in Passes. often Passes generate an explicit output file In each pass whole input file is processed. Issues Driving Compiler Design Correctness Speed (runtime and compile time) https://www.slideshare.net/Amansharma1037 https://www.linkedin.com/in/includeaman
  • 14. Degrees of optimization Multiple passes Space Feedback to user Debugging Other Applications In addition to the development of a compiler, the techniques used in compiler design can be applicable to many problems in computer science. Techniques used in a lexical analyzer can be used in text editors, information retrieval system, and pattern recognition programs. Techniques used in a parser can be used in a query processing system such as SQL. Many software having a complex front-end may need techniques used in compiler design. A symbolic equation solver which takes an equation as input.That program should parse the given input equation. Most of the techniques used in compiler design can be used in Natural Language Processing (NLP) systems. https://www.slideshare.net/Amansharma1037 https://www.linkedin.com/in/includeaman