SlideShare a Scribd company logo
1 of 19
Download to read offline
Compiler Construction
Lecture Slides
Compilers
• Programming languages are notations for describing computation to
people and to machines
• All the software (including Operating Systems, Embedded Software, Special
Purpose Software, General Software applications) running on the
computers was written in some programming language.
• Types of languages:
• High level language (C++, Java, C-sharp etc.)
• Low level language (one-to-one interaction with Machine e.g., Assembly)
• Machine level language (Interact directly with Machine’s Hardware in the form of
101010….)
• There must be a translation mechanism that tells machine what to do against each set
of instruction
Compilers
• A program must be translated into a form in which it can be executed
by a computer
• The software systems that do this translation are called “COMPILERS”
Program in Program in
Source Language Target
(High level) Language
(Machine Level)
Errors
Compiler
Objective
• The purpose of this course is to become familiar with the
functionality of different Phases in the construction of a compiler
front end and to gain insight of how these phases are related to each
other.
• Process of construction of compiler
• Lexical analysis
• Syntax Analysis
• Semantic Analysis
• Syntax Directed Translation
• Intermediate Code Representation
Language Processors
• Simply stated, a compiler is a program that can read a program in one
language – the source language – and translate into an equivalent
program in another language – the target language.
Source Program
• Important Role
• Report errors, if any, found in source program
Target Program
Compiler
Language Processors
• If the target program is an executable machine-language program, it
can then be called by the user to process inputs and produce outputs.
input output
Target Program
Interpreter
• Interpreters are the common kind of language processor.
• An interpreter appears to directly execute the program and provide
output.
Source Program
input output
Errors
Interpreter
Compiler Vs Interpreter
Compiler Interpreter
Pros Pros
Less space Easy debugging
Fast Execution Fast Development
Cons Cons
Slow Processing Not for large project
(Partly solved; Requires more space
Separate compilation) Slower Execution
Debugging (Interpreter in memory
(Improves through IDEs) all the time)
Language Processors
• Example
Java language processors combine compilation and interpretation
source Program
Intermediate Program
output
input
A Hybrid Compiler
Virtual
Machine
Translator
Language Processors
• A Java source program may first be compiled into an intermediate form
called bytecodes.
• The bytecodes are then interpreted by a virtual machine.
• A benefit of this arrangement is that bytecodes compiled on one machine
can be interpreted on another machine, perhaps across a network.
• In order to achieve faster processing of inputs to outputs, some Java
compilers use just-in-time compilers
• It translate the bytecodes into machine language immediately before they run the
intermediate program to process the input.
• In addition to a compiler, several other programs may be required to create
an executable target program.
Language Processors
• A source program may be divided into modules stored in separate files.
• The task of collecting the source program is sometimes entrusted to a
separate program, called a preprocessor.
• The preprocessor may also expand “shorthands” called macros into source
language statements.
• The modified source program is then fed to a compiler.
• The compiler may produce an assembly-language program as its output,
because assembly language is easier to produce as output and is easier to
debug.
• The assembly language is then processed by a program called an assembler
that produces machine code as its output.
Language Processors
• Large programs are often compiled in pieces, so the machine code
may have to be linked together with other object files and library files
into the code that actually runs on the machine.
• The linker resolves external memory addresses, where the code in
one file may refer to a location in another file.
• The loader then puts together all of the executable objects files into
memory of execution.
Language Processors
Language Processing System
Structure of Compiler
• .
Structure of Compiler
• .
Analysis
• Operations performed
• Breaks up the source program in to pieces
• Imposes a grammatical structure on these pieces
• Then an intermediate representation (known as Tree Structure = Syntax Tree, in
which we got to know all of the insight operations performed and their hierarchy) is
created using this structure
• Display an error messages (if any)
• It also collects information about the source program and stores in a data structure
called symbol table (Symbol table is used in all compilation phases whether directly
or in any of its updated form)
• Analysis phase is also known as “Front end of a compiler”
Synthesis
• Operations performed
• It takes the intermediate representation and information from the symbol
tree as input.
• Construct the desired target program
• Back End of a Compiler
Compilation Phases
• A typical decomposition of a
compiler can be done into
several phases:

More Related Content

Similar to Week 08_Basics of Compiler Construction.pdf

Introduction_to_Programming.pptx
Introduction_to_Programming.pptxIntroduction_to_Programming.pptx
Introduction_to_Programming.pptxPmarkNorcio
 
Compiler an overview
Compiler  an overviewCompiler  an overview
Compiler an overviewamudha arul
 
introduction computer programming languages
introduction computer programming languages introduction computer programming languages
introduction computer programming languages BakhatAli3
 
X-CS-8.0 Programming in C Language 2022-2023.pdf
X-CS-8.0 Programming in C Language 2022-2023.pdfX-CS-8.0 Programming in C Language 2022-2023.pdf
X-CS-8.0 Programming in C Language 2022-2023.pdfAlefya1
 
Life cycle of a computer program
Life cycle of a computer programLife cycle of a computer program
Life cycle of a computer programAbhay Kumar
 
Introduction to computer programming
Introduction to computer programming Introduction to computer programming
Introduction to computer programming VanessaBuensalida
 
Programming languages,compiler,interpreter,softwares
Programming languages,compiler,interpreter,softwaresProgramming languages,compiler,interpreter,softwares
Programming languages,compiler,interpreter,softwaresNisarg Amin
 
Interaction With Computers FIT
Interaction With Computers FITInteraction With Computers FIT
Interaction With Computers FITRaj vardhan
 
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
 
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
 
Python-unit -I.pptx
Python-unit -I.pptxPython-unit -I.pptx
Python-unit -I.pptxcrAmth
 
Programming Languages / Translators
Programming Languages / TranslatorsProgramming Languages / Translators
Programming Languages / TranslatorsProject Student
 
Language translator
Language translatorLanguage translator
Language translatorasmakh89
 
4 computer languages
4 computer languages4 computer languages
4 computer languagesBaliThorat1
 

Similar to Week 08_Basics of Compiler Construction.pdf (20)

Introduction_to_Programming.pptx
Introduction_to_Programming.pptxIntroduction_to_Programming.pptx
Introduction_to_Programming.pptx
 
Compiler an overview
Compiler  an overviewCompiler  an overview
Compiler an overview
 
introduction computer programming languages
introduction computer programming languages introduction computer programming languages
introduction computer programming languages
 
Chap01-Intro.ppt
Chap01-Intro.pptChap01-Intro.ppt
Chap01-Intro.ppt
 
X-CS-8.0 Programming in C Language 2022-2023.pdf
X-CS-8.0 Programming in C Language 2022-2023.pdfX-CS-8.0 Programming in C Language 2022-2023.pdf
X-CS-8.0 Programming in C Language 2022-2023.pdf
 
Life cycle of a computer program
Life cycle of a computer programLife cycle of a computer program
Life cycle of a computer program
 
sege.pdf
sege.pdfsege.pdf
sege.pdf
 
Introduction to computer programming
Introduction to computer programming Introduction to computer programming
Introduction to computer programming
 
Programming languages,compiler,interpreter,softwares
Programming languages,compiler,interpreter,softwaresProgramming languages,compiler,interpreter,softwares
Programming languages,compiler,interpreter,softwares
 
programming.pptx
programming.pptxprogramming.pptx
programming.pptx
 
a1.pptx.pdf
a1.pptx.pdfa1.pptx.pdf
a1.pptx.pdf
 
Interaction With Computers FIT
Interaction With Computers FITInteraction With Computers FIT
Interaction With Computers FIT
 
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
 
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
 
Python-unit -I.pptx
Python-unit -I.pptxPython-unit -I.pptx
Python-unit -I.pptx
 
Programming Languages / Translators
Programming Languages / TranslatorsProgramming Languages / Translators
Programming Languages / Translators
 
Language translator
Language translatorLanguage translator
Language translator
 
4 computer languages
4 computer languages4 computer languages
4 computer languages
 

Recently uploaded

"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr LapshynFwdays
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphNeo4j
 
APIForce Zurich 5 April Automation LPDG
APIForce Zurich 5 April  Automation LPDGAPIForce Zurich 5 April  Automation LPDG
APIForce Zurich 5 April Automation LPDGMarianaLemus7
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsAndrey Dotsenko
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptxLBM Solutions
 
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsSnow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsHyundai Motor Group
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 

Recently uploaded (20)

"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
 
APIForce Zurich 5 April Automation LPDG
APIForce Zurich 5 April  Automation LPDGAPIForce Zurich 5 April  Automation LPDG
APIForce Zurich 5 April Automation LPDG
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptx
 
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsSnow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 

Week 08_Basics of Compiler Construction.pdf

  • 2. Compilers • Programming languages are notations for describing computation to people and to machines • All the software (including Operating Systems, Embedded Software, Special Purpose Software, General Software applications) running on the computers was written in some programming language. • Types of languages: • High level language (C++, Java, C-sharp etc.) • Low level language (one-to-one interaction with Machine e.g., Assembly) • Machine level language (Interact directly with Machine’s Hardware in the form of 101010….) • There must be a translation mechanism that tells machine what to do against each set of instruction
  • 3. Compilers • A program must be translated into a form in which it can be executed by a computer • The software systems that do this translation are called “COMPILERS” Program in Program in Source Language Target (High level) Language (Machine Level) Errors Compiler
  • 4. Objective • The purpose of this course is to become familiar with the functionality of different Phases in the construction of a compiler front end and to gain insight of how these phases are related to each other. • Process of construction of compiler • Lexical analysis • Syntax Analysis • Semantic Analysis • Syntax Directed Translation • Intermediate Code Representation
  • 5. Language Processors • Simply stated, a compiler is a program that can read a program in one language – the source language – and translate into an equivalent program in another language – the target language. Source Program • Important Role • Report errors, if any, found in source program Target Program Compiler
  • 6. Language Processors • If the target program is an executable machine-language program, it can then be called by the user to process inputs and produce outputs. input output Target Program
  • 7. Interpreter • Interpreters are the common kind of language processor. • An interpreter appears to directly execute the program and provide output. Source Program input output Errors Interpreter
  • 8. Compiler Vs Interpreter Compiler Interpreter Pros Pros Less space Easy debugging Fast Execution Fast Development Cons Cons Slow Processing Not for large project (Partly solved; Requires more space Separate compilation) Slower Execution Debugging (Interpreter in memory (Improves through IDEs) all the time)
  • 9. Language Processors • Example Java language processors combine compilation and interpretation source Program Intermediate Program output input A Hybrid Compiler Virtual Machine Translator
  • 10. Language Processors • A Java source program may first be compiled into an intermediate form called bytecodes. • The bytecodes are then interpreted by a virtual machine. • A benefit of this arrangement is that bytecodes compiled on one machine can be interpreted on another machine, perhaps across a network. • In order to achieve faster processing of inputs to outputs, some Java compilers use just-in-time compilers • It translate the bytecodes into machine language immediately before they run the intermediate program to process the input. • In addition to a compiler, several other programs may be required to create an executable target program.
  • 11. Language Processors • A source program may be divided into modules stored in separate files. • The task of collecting the source program is sometimes entrusted to a separate program, called a preprocessor. • The preprocessor may also expand “shorthands” called macros into source language statements. • The modified source program is then fed to a compiler. • The compiler may produce an assembly-language program as its output, because assembly language is easier to produce as output and is easier to debug. • The assembly language is then processed by a program called an assembler that produces machine code as its output.
  • 12. Language Processors • Large programs are often compiled in pieces, so the machine code may have to be linked together with other object files and library files into the code that actually runs on the machine. • The linker resolves external memory addresses, where the code in one file may refer to a location in another file. • The loader then puts together all of the executable objects files into memory of execution.
  • 17. Analysis • Operations performed • Breaks up the source program in to pieces • Imposes a grammatical structure on these pieces • Then an intermediate representation (known as Tree Structure = Syntax Tree, in which we got to know all of the insight operations performed and their hierarchy) is created using this structure • Display an error messages (if any) • It also collects information about the source program and stores in a data structure called symbol table (Symbol table is used in all compilation phases whether directly or in any of its updated form) • Analysis phase is also known as “Front end of a compiler”
  • 18. Synthesis • Operations performed • It takes the intermediate representation and information from the symbol tree as input. • Construct the desired target program • Back End of a Compiler
  • 19. Compilation Phases • A typical decomposition of a compiler can be done into several phases: