SlideShare a Scribd company logo
INTRODUCTION TO COMPILERS
UNIT 1
Syllabus:
Translator – Compilation and Interpretation, language processors; The phase of compiler – Errors
Encountered in Different Phases, The Grouping of phases; Compiler Construction Tools; Programming
Language Basics.
SYLLABUS
TRANSLATOR
 Translator is a program that takes as input a program written in one
programming language (the source language) and produces as output a program
in another language (the object or target language).
COMPILER
 A compiler is a program that can read a program in one language, the
source language, and translate it into an equivalent program in another
language - the target language
If the target program is an executable machine-
language program, it can then be called by the
user to process inputs and produce outputs;
Note:An important role of the
compiler is to report any
errors in the source program
that it detects during the
translation process.
INTERPRETER
 An interpreter is another common kind of language processor.
 Instead of producing a target program as a translation, an interpreter
appears to directly execute the operations specified in the source
program on inputs supplied by the user.
 The machine-language target program produced by a compiler is usually
much faster than an interpreter at mapping inputs to outputs .
 An interpreter, however, can usually give better error diagnostics than a
compiler, because it executes the source program statement by statement
• Java language processors combine compilation and interpretation.
• A Java source program may first be compiled into an intermediate form called
bytecodes interpreted by virtual machine.
compiled on one machine can be
interpreted on another machine
across a network
Achieve faster processing of inputs to outputs:
Java compilers, called just-in-time compilers, translate
the bytecodes into machine language immediately before
they run the intermediate program to process the input
Introduction to Compiler Design Structutre, Phases
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 shorthand's, 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 relocatable machine code as its output.
• Large programs are often compiled in pieces, so the relocatable machine code may
have to be linked together with other relocatable 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 object files into memory for
execution.
THE STRUCTURE OF A COMPILER
• A compiler is treated as a single box that maps a source program into a semantically
equivalent target program.
• There are two parts to this mapping: analysis part and synthesis part
• The analysis part is often called the front end of the compiler; the synthesis part is the
back end of the compiler.
ANALYSIS
 It breaks up the source program into constituent pieces and imposes a grammatical structure
on them.
 It detects that the source program is either syntactically ill formed or semantically unsound, then it must
provide informative messages, so the user can take corrective action
 This structure to create an intermediate representation of the source program
 It also collects information about the source program and stores it in a data structure called a
symbol table, which is passed along with the intermediate representation to the synthesis part
SYNTHESIS
• In this part, it constructs the desired target program from the
intermediate representation and the information in the symbol table
THE PHASES OF A COMPILER
The symbol table, which
stores information about
the entire source
program, is used by all
phases of the compiler
The purpose of this optimization phase
is to perform transformations on the
intermediate representation, the
backend can produce a better target
program
HOW DOES ITWORKING
19
Scanner Parser
Semantic
Routines
Code
Generator
Optimizer
Source
Program Tokens Syntactic
Structure
Symbol and
Attribute
Tables
(Used by all Phases of The Compiler)
(Character Stream)
Intermediate
Representation
Target machine code
20
THE STRUCTURE OF A COMPILER (3)
Scanner Parser
Semantic
Routines
Code
Generator
Optimizer
Source
Program Tokens Syntactic
Structure
Symbol and
Attribute
Tables
(Used by all
Phases of
The Compiler)
Scanner
 The scanner begins the analysis of the source program by reading the input,
character by character, and grouping characters into individual words and
symbols (tokens)
 RE ( Regular expression )
 NFA ( Non-deterministic Finite Automata )
 DFA ( Deterministic Finite Automata )
 LEX
(Character Stream)
Intermediate
Representation
Target machine code
21
THE STRUCTURE OF A COMPILER (4)
Scanner Parser
Semantic
Routines
Code
Generator
Optimizer
Source
Program Tokens Syntactic
Structure
Symbol and
Attribute
Tables
(Used by all
Phases of
The Compiler)
Parser
 Given a formal syntax specification (typically as a context-free grammar
[CFG] ), the parse reads tokens and groups them into units as specified by the
productions of the CFG being used.
 As syntactic structure is recognized, the parser either calls corresponding
semantic routines directly or builds a syntax tree.
 CFG ( Context-Free Grammar )
 BNF ( Backus-Naur Form )
 GAA ( Grammar Analysis Algorithms )
 LL, LR, SLR, LALR Parsers
 YACC
(Character Stream)
Intermediate
Representation
Target machine code
22
THE STRUCTURE OF A COMPILER (5)
Scanner Parser
Semantic
Routines
Code
Generator
Optimizer
Source
Program
(Character Stream)
Tokens Syntactic
Structure
Intermediate
Representation
Symbol and
Attribute
Tables
(Used by all
Phases of
The Compiler)
Semantic Routines
 Perform two functions
 Check the static semantics of each construct
 Do the actual translation
 The heart of a compiler
 Syntax Directed Translation
 Semantic Processing Techniques
 IR (Intermediate Representation)
Target machine code
23
THE STRUCTURE OF A COMPILER (6)
Scanner Parser
Semantic
Routines
Code
Generator
Optimizer
Source
Program Tokens Syntactic
Structure
Symbol and
Attribute
Tables
(Used by all
Phases of
The Compiler)
Optimizer
 The IR code generated by the semantic routines is analyzed and transformed
into functionally equivalent but improved IR code
 This phase can be very complex and slow
 Peephole optimization
 loop optimization, register allocation, code scheduling
 Register and Temporary Management
 Peephole Optimization
(Character Stream)
Intermediate
Representation
Target machine code
24
THE STRUCTURE OF A COMPILER (7)
Source
Program
(Character Stream)
Scanner
Tokens
Parser
Syntactic
Structure
Semantic
Routines
Intermediate
Representation
Optimizer
Code
Generator
Code Generator
 Interpretive Code Generation
 Generating Code from Tree/Dag
 Grammar-Based Code Generator
Target machine code
25
THE STRUCTURE OF A COMPILER (8)
Scanner
[Lexical Analyzer]
Parser
[Syntax Analyzer]
Semantic Process
[Semantic analyzer]
Code Generator
[Intermediate Code Generator]
Code Optimizer
Tokens
Parse tree
Abstract Syntax Tree w/ Attributes
Non-optimized Intermediate Code
Optimized Intermediate Code
Code Optimizer
Target machine code

More Related Content

Similar to Introduction to Compiler Design Structutre, Phases (20)

PDF
3_1_COMPILER_DESIGNGARGREREGREGREGREGREGRGRERE
solomonraju17
 
PDF
design intoduction of_COMPILER_DESIGN.pdf
advRajatSharma
 
PDF
COMPILER DESIGN Engineering learinin.pdf
TechSkills7
 
PPTX
Chapter 1.pptx
NesredinTeshome1
 
PPTX
COMPILER DESIGN PPTS.pptx
MUSHAMHARIKIRAN6737
 
PPTX
Chapter-1.pptx compiler Design Course Material
gadisaAdamu
 
PPTX
Compiler Design Introduction With Design
rashmishekhar81
 
PPT
Introduction to Compiler Construction
Sarmad Ali
 
PPT
Compiler Design Basics
Akhil Kaushik
 
PPTX
Chapter 2 Program language translation.pptx
dawod yimer
 
PPTX
Pros and cons of c as a compiler language
Ashok Raj
 
PPTX
CD U1-5.pptx
Himajanaidu2
 
PDF
Compiler design
sanchi29
 
PPTX
Lecture 1 introduction to language processors
Rebaz Najeeb
 
PPTX
Ch 1.pptx
woldu2
 
PPT
Compiler Construction introduction
Rana Ehtisham Ul Haq
 
PPTX
Unit2_CD.pptx more about compilation of the day
k12196987
 
PPT
cd-greeshma (1).ppt compiler design unit 1
vrawat4
 
PPT
cd-greeshma.ppt online downloaded for study
yashashreeg2307
 
PPT
Cd unit i
Abhimanyu Mishra
 
3_1_COMPILER_DESIGNGARGREREGREGREGREGREGRGRERE
solomonraju17
 
design intoduction of_COMPILER_DESIGN.pdf
advRajatSharma
 
COMPILER DESIGN Engineering learinin.pdf
TechSkills7
 
Chapter 1.pptx
NesredinTeshome1
 
COMPILER DESIGN PPTS.pptx
MUSHAMHARIKIRAN6737
 
Chapter-1.pptx compiler Design Course Material
gadisaAdamu
 
Compiler Design Introduction With Design
rashmishekhar81
 
Introduction to Compiler Construction
Sarmad Ali
 
Compiler Design Basics
Akhil Kaushik
 
Chapter 2 Program language translation.pptx
dawod yimer
 
Pros and cons of c as a compiler language
Ashok Raj
 
CD U1-5.pptx
Himajanaidu2
 
Compiler design
sanchi29
 
Lecture 1 introduction to language processors
Rebaz Najeeb
 
Ch 1.pptx
woldu2
 
Compiler Construction introduction
Rana Ehtisham Ul Haq
 
Unit2_CD.pptx more about compilation of the day
k12196987
 
cd-greeshma (1).ppt compiler design unit 1
vrawat4
 
cd-greeshma.ppt online downloaded for study
yashashreeg2307
 
Cd unit i
Abhimanyu Mishra
 

Recently uploaded (20)

PPTX
Soil and agriculture microbiology .pptx
Keerthana Ramesh
 
PDF
Generative AI: it's STILL not a robot (CIJ Summer 2025)
Paul Bradshaw
 
PPSX
HEALTH ASSESSMENT (Community Health Nursing) - GNM 1st Year
Priyanshu Anand
 
PPTX
Unit 2 COMMERCIAL BANKING, Corporate banking.pptx
AnubalaSuresh1
 
PPTX
ASRB NET 2023 PREVIOUS YEAR QUESTION PAPER GENETICS AND PLANT BREEDING BY SAT...
Krashi Coaching
 
PPTX
Stereochemistry-Optical Isomerism in organic compoundsptx
Tarannum Nadaf-Mansuri
 
PDF
LAW OF CONTRACT (5 YEAR LLB & UNITARY LLB )- MODULE - 1.& 2 - LEARN THROUGH P...
APARNA T SHAIL KUMAR
 
PDF
DIGESTION OF CARBOHYDRATES,PROTEINS,LIPIDS
raviralanaresh2
 
PDF
ARAL_Orientation_Day-2-Sessions_ARAL-Readung ARAL-Mathematics ARAL-Sciencev2.pdf
JoelVilloso1
 
PPTX
How to Manage Large Scrollbar in Odoo 18 POS
Celine George
 
PDF
People & Earth's Ecosystem -Lesson 2: People & Population
marvinnbustamante1
 
PDF
CEREBRAL PALSY: NURSING MANAGEMENT .pdf
PRADEEP ABOTHU
 
PPTX
PATIENT ASSIGNMENTS AND NURSING CARE RESPONSIBILITIES.pptx
PRADEEP ABOTHU
 
PPTX
HYDROCEPHALUS: NURSING MANAGEMENT .pptx
PRADEEP ABOTHU
 
PDF
IMP NAAC REFORMS 2024 - 10 Attributes.pdf
BHARTIWADEKAR
 
PPTX
How to Convert an Opportunity into a Quotation in Odoo 18 CRM
Celine George
 
PPTX
Growth and development and milestones, factors
BHUVANESHWARI BADIGER
 
PPTX
PPT on the Development of Education in the Victorian England
Beena E S
 
PDF
ARAL-Orientation_Morning-Session_Day-11.pdf
JoelVilloso1
 
PDF
Zoology (Animal Physiology) practical Manual
raviralanaresh2
 
Soil and agriculture microbiology .pptx
Keerthana Ramesh
 
Generative AI: it's STILL not a robot (CIJ Summer 2025)
Paul Bradshaw
 
HEALTH ASSESSMENT (Community Health Nursing) - GNM 1st Year
Priyanshu Anand
 
Unit 2 COMMERCIAL BANKING, Corporate banking.pptx
AnubalaSuresh1
 
ASRB NET 2023 PREVIOUS YEAR QUESTION PAPER GENETICS AND PLANT BREEDING BY SAT...
Krashi Coaching
 
Stereochemistry-Optical Isomerism in organic compoundsptx
Tarannum Nadaf-Mansuri
 
LAW OF CONTRACT (5 YEAR LLB & UNITARY LLB )- MODULE - 1.& 2 - LEARN THROUGH P...
APARNA T SHAIL KUMAR
 
DIGESTION OF CARBOHYDRATES,PROTEINS,LIPIDS
raviralanaresh2
 
ARAL_Orientation_Day-2-Sessions_ARAL-Readung ARAL-Mathematics ARAL-Sciencev2.pdf
JoelVilloso1
 
How to Manage Large Scrollbar in Odoo 18 POS
Celine George
 
People & Earth's Ecosystem -Lesson 2: People & Population
marvinnbustamante1
 
CEREBRAL PALSY: NURSING MANAGEMENT .pdf
PRADEEP ABOTHU
 
PATIENT ASSIGNMENTS AND NURSING CARE RESPONSIBILITIES.pptx
PRADEEP ABOTHU
 
HYDROCEPHALUS: NURSING MANAGEMENT .pptx
PRADEEP ABOTHU
 
IMP NAAC REFORMS 2024 - 10 Attributes.pdf
BHARTIWADEKAR
 
How to Convert an Opportunity into a Quotation in Odoo 18 CRM
Celine George
 
Growth and development and milestones, factors
BHUVANESHWARI BADIGER
 
PPT on the Development of Education in the Victorian England
Beena E S
 
ARAL-Orientation_Morning-Session_Day-11.pdf
JoelVilloso1
 
Zoology (Animal Physiology) practical Manual
raviralanaresh2
 
Ad

Introduction to Compiler Design Structutre, Phases

  • 2. Syllabus: Translator – Compilation and Interpretation, language processors; The phase of compiler – Errors Encountered in Different Phases, The Grouping of phases; Compiler Construction Tools; Programming Language Basics. SYLLABUS
  • 3. TRANSLATOR  Translator is a program that takes as input a program written in one programming language (the source language) and produces as output a program in another language (the object or target language).
  • 4. COMPILER  A compiler is a program that can read a program in one language, the source language, and translate it into an equivalent program in another language - the target language
  • 5. If the target program is an executable machine- language program, it can then be called by the user to process inputs and produce outputs; Note:An important role of the compiler is to report any errors in the source program that it detects during the translation process.
  • 6. INTERPRETER  An interpreter is another common kind of language processor.  Instead of producing a target program as a translation, an interpreter appears to directly execute the operations specified in the source program on inputs supplied by the user.
  • 7.  The machine-language target program produced by a compiler is usually much faster than an interpreter at mapping inputs to outputs .  An interpreter, however, can usually give better error diagnostics than a compiler, because it executes the source program statement by statement
  • 8. • Java language processors combine compilation and interpretation. • A Java source program may first be compiled into an intermediate form called bytecodes interpreted by virtual machine. compiled on one machine can be interpreted on another machine across a network Achieve faster processing of inputs to outputs: Java compilers, called just-in-time compilers, translate the bytecodes into machine language immediately before they run the intermediate program to process the input
  • 11. • 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 shorthand's, called macros, into source language statements.
  • 12. • 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.
  • 13. • The assembly language is then processed by a program called an assembler that produces relocatable machine code as its output. • Large programs are often compiled in pieces, so the relocatable machine code may have to be linked together with other relocatable object files and library files into the code that actually runs on the machine.
  • 14. • 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 object files into memory for execution.
  • 15. THE STRUCTURE OF A COMPILER • A compiler is treated as a single box that maps a source program into a semantically equivalent target program. • There are two parts to this mapping: analysis part and synthesis part • The analysis part is often called the front end of the compiler; the synthesis part is the back end of the compiler.
  • 16. ANALYSIS  It breaks up the source program into constituent pieces and imposes a grammatical structure on them.  It detects that the source program is either syntactically ill formed or semantically unsound, then it must provide informative messages, so the user can take corrective action  This structure to create an intermediate representation of the source program  It also collects information about the source program and stores it in a data structure called a symbol table, which is passed along with the intermediate representation to the synthesis part
  • 17. SYNTHESIS • In this part, it constructs the desired target program from the intermediate representation and the information in the symbol table
  • 18. THE PHASES OF A COMPILER The symbol table, which stores information about the entire source program, is used by all phases of the compiler The purpose of this optimization phase is to perform transformations on the intermediate representation, the backend can produce a better target program
  • 19. HOW DOES ITWORKING 19 Scanner Parser Semantic Routines Code Generator Optimizer Source Program Tokens Syntactic Structure Symbol and Attribute Tables (Used by all Phases of The Compiler) (Character Stream) Intermediate Representation Target machine code
  • 20. 20 THE STRUCTURE OF A COMPILER (3) Scanner Parser Semantic Routines Code Generator Optimizer Source Program Tokens Syntactic Structure Symbol and Attribute Tables (Used by all Phases of The Compiler) Scanner  The scanner begins the analysis of the source program by reading the input, character by character, and grouping characters into individual words and symbols (tokens)  RE ( Regular expression )  NFA ( Non-deterministic Finite Automata )  DFA ( Deterministic Finite Automata )  LEX (Character Stream) Intermediate Representation Target machine code
  • 21. 21 THE STRUCTURE OF A COMPILER (4) Scanner Parser Semantic Routines Code Generator Optimizer Source Program Tokens Syntactic Structure Symbol and Attribute Tables (Used by all Phases of The Compiler) Parser  Given a formal syntax specification (typically as a context-free grammar [CFG] ), the parse reads tokens and groups them into units as specified by the productions of the CFG being used.  As syntactic structure is recognized, the parser either calls corresponding semantic routines directly or builds a syntax tree.  CFG ( Context-Free Grammar )  BNF ( Backus-Naur Form )  GAA ( Grammar Analysis Algorithms )  LL, LR, SLR, LALR Parsers  YACC (Character Stream) Intermediate Representation Target machine code
  • 22. 22 THE STRUCTURE OF A COMPILER (5) Scanner Parser Semantic Routines Code Generator Optimizer Source Program (Character Stream) Tokens Syntactic Structure Intermediate Representation Symbol and Attribute Tables (Used by all Phases of The Compiler) Semantic Routines  Perform two functions  Check the static semantics of each construct  Do the actual translation  The heart of a compiler  Syntax Directed Translation  Semantic Processing Techniques  IR (Intermediate Representation) Target machine code
  • 23. 23 THE STRUCTURE OF A COMPILER (6) Scanner Parser Semantic Routines Code Generator Optimizer Source Program Tokens Syntactic Structure Symbol and Attribute Tables (Used by all Phases of The Compiler) Optimizer  The IR code generated by the semantic routines is analyzed and transformed into functionally equivalent but improved IR code  This phase can be very complex and slow  Peephole optimization  loop optimization, register allocation, code scheduling  Register and Temporary Management  Peephole Optimization (Character Stream) Intermediate Representation Target machine code
  • 24. 24 THE STRUCTURE OF A COMPILER (7) Source Program (Character Stream) Scanner Tokens Parser Syntactic Structure Semantic Routines Intermediate Representation Optimizer Code Generator Code Generator  Interpretive Code Generation  Generating Code from Tree/Dag  Grammar-Based Code Generator Target machine code
  • 25. 25 THE STRUCTURE OF A COMPILER (8) Scanner [Lexical Analyzer] Parser [Syntax Analyzer] Semantic Process [Semantic analyzer] Code Generator [Intermediate Code Generator] Code Optimizer Tokens Parse tree Abstract Syntax Tree w/ Attributes Non-optimized Intermediate Code Optimized Intermediate Code Code Optimizer Target machine code