SlideShare a Scribd company logo
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

PPTX
Lec 1 Compiler Construction (CC) CC.pptx
PPTX
Compiler Construction from very basic start
PPT
Compiler Design Basics
PPTX
Compiler Design Introduction
PPTX
basic programming introduction about java
PPT
Introduction to C for Btech 1st year.ppt
PPT
Compiler Design Basics
PPTX
Compilers.pptx
Lec 1 Compiler Construction (CC) CC.pptx
Compiler Construction from very basic start
Compiler Design Basics
Compiler Design Introduction
basic programming introduction about java
Introduction to C for Btech 1st year.ppt
Compiler Design Basics
Compilers.pptx

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

PPTX
Computer Science guide to C Unit-I Translator.pptx
PPT
Session01 basics programming
PPTX
Introduction to Compilers
PDF
Chapter1.pdf
PPT
Introduction to Compiler design
PPT
Introduction to compiler design and phases of compiler
PPTX
Introduction_to_Programming.pptx
PPTX
Compiler an overview
PPT
introduction computer programming languages
PPT
introduction to computer programming and its examples
PPT
presentation of Programing fundamental.
PPT
Introduction Computer programming and operating system
PDF
Module4.pdf ,...................................
PPTX
computer programming and hardware technique
PPT
Lahor main It revoloution anfd its uses.
PPT
basics of it in pakistan and all over the
PPTX
Agro informatics centre up State of Lec 6.pptx
PPTX
Compiler Design Introduction With Design
PPT
Chap01-Intro.ppt
PDF
X-CS-8.0 Programming in C Language 2022-2023.pdf
Computer Science guide to C Unit-I Translator.pptx
Session01 basics programming
Introduction to Compilers
Chapter1.pdf
Introduction to Compiler design
Introduction to compiler design and phases of compiler
Introduction_to_Programming.pptx
Compiler an overview
introduction computer programming languages
introduction to computer programming and its examples
presentation of Programing fundamental.
Introduction Computer programming and operating system
Module4.pdf ,...................................
computer programming and hardware technique
Lahor main It revoloution anfd its uses.
basics of it in pakistan and all over the
Agro informatics centre up State of Lec 6.pptx
Compiler Design Introduction With Design
Chap01-Intro.ppt
X-CS-8.0 Programming in C Language 2022-2023.pdf
Ad

Recently uploaded (20)

PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PDF
Encapsulation theory and applications.pdf
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PPTX
MYSQL Presentation for SQL database connectivity
PPTX
Spectroscopy.pptx food analysis technology
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PPTX
sap open course for s4hana steps from ECC to s4
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PDF
Machine learning based COVID-19 study performance prediction
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PPTX
Big Data Technologies - Introduction.pptx
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PPTX
Cloud computing and distributed systems.
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
 
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
Encapsulation theory and applications.pdf
Encapsulation_ Review paper, used for researhc scholars
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
Diabetes mellitus diagnosis method based random forest with bat algorithm
MYSQL Presentation for SQL database connectivity
Spectroscopy.pptx food analysis technology
Per capita expenditure prediction using model stacking based on satellite ima...
Digital-Transformation-Roadmap-for-Companies.pptx
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
20250228 LYD VKU AI Blended-Learning.pptx
sap open course for s4hana steps from ECC to s4
Agricultural_Statistics_at_a_Glance_2022_0.pdf
NewMind AI Weekly Chronicles - August'25 Week I
Machine learning based COVID-19 study performance prediction
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Big Data Technologies - Introduction.pptx
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Cloud computing and distributed systems.
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
 
Ad

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: