SlideShare a Scribd company logo
1 of 26
Introduction to Compiler
Construction
Prof. A. N. Kazi
Jawaharlal Darda Institute of Engineering &
Technology, Yavatmal
TRANSLATORS
• A translator is one kind of program that takes one form
of program (input) and converts into another form
(output). The input program is called source language
and the output program is called target language.
Types of Translators are ::
(1) Compilers
(2) Interpreters
(3) Assemblers
COMPILATION AND INTERPRETATION
• A compiler is a program that reads a program in one
language and translates it into an equivalent program
in another language. The translation done by a
compiler is called compilation.
• 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.
COMPILATION AND INTERPRETATION
 Compiler :
 Interpreter :
Compilers
• “Compilation”
– Translation of a program written in a source
language into a semantically equivalent
program written in a target language
Compiler
Error messages
Source
Program
Target
Program
Input
Output
As an important role of a compiler is error showing to
the programmer.
INTERPRETER
• An interpreter is a program that appears to execute a
source program as if it were machine language.
Fig: Execution in Interpreter
Languages such as BASIC, SNOBOL, LISP can be translated
using interpreters
Compiler is a translator program that translates a program written in
(HLL) the source program and translate it into an equivalent program in
(MLL) the target program.
Fig : Language Processing System
HLL Consisting
#include< >
#define SIZE
Pure HLL
Fig : Structure of Compiler
Fig : Execution process of source program in Compiler
ASSEMBLER
1. Programmers found it difficult to write or read programs in
machine language. They begin to use a mnemonic (symbols) for
each machine instruction, which they would subsequently translate
into machine language.
2. Such a mnemonic machine language is now called an assembly
language.(ALP)
3. Programs known as assembler were written to automate the
translation of assembly language in to machine language.
LOADER AND LINK-EDITOR:
• Loader : Once the assembler procedures an object
program, that program must be placed into memory and
executed. The assembler could place the object program
directly in memory and transfer control to it, thereby
causing the machine language program to be execute.
• Linker : Add necessary library file that are included in
source program
LIST OF COMPILERS
1. Ada compilers
2 .ALGOL compilers
3 .BASIC compilers
4 .C# compilers
5 .C compilers
6 .C++ compilers
7 .COBOL compilers
8 .Common Lisp compilers
9. ECMAScript interpreters
10. Fortran compilers
11 .Java compilers
12. Pascal compilers
13. PL/I compilers
14. Python compilers
15. Smalltalk compilers
Preprocessors, Compilers, Assemblers,
and Linkers
Preprocessor
Compiler
Assembler
Linker
Skeletal Source Program
Source Program
Target Assembly Program
Relocatable Object Code
Absolute Machine Code
Libraries and
Relocatable Object Files
Try for example:
gcc -v myprog.c
Phases of a compiler
• Lexical Analysis
- The first phase of a compiler is called lexical
analysis or scanning or linear analysis. The lexical
analyzer reads the stream of characters making up
the source program and groups the characters into
meaningful sequences called lexemes.
For each lexeme, the lexical analyzer produces output as a token of
the form
<token-name, attribute-value>
The first component token-name is an abstract symbol that is used
during syntax analysis, and the second component attribute-value
points to an entry in the symbol table for this token.
Lexeme mapped in Tokens
1) position is a lexeme that would be mapped into a token
<id,1>.
where , id is an abstract symbol standing for identifier and 1
points to the symbol able entry for position.
(2) The assignment symbol = is a lexeme that is mapped into
the token <=>.
(3) initial is a lexeme that is mapped into the token <id, 2>.
(4) + is a lexeme that is mapped into the token <+>.
(5) rate is a lexeme that is mapped into the token <id, 3>.
(6) * is a lexeme that is mapped into the token <*>.
(7) 60 is a lexeme that is mapped into the token <60>.
The sequence of tokens produced as follows after lexical analysis.
<id, 1> <=> <id, 2> <+> <id, 3> <*> <60>
Syntax Analysis
• The second phase of the compiler is syntax analysis or
parsing or hierarchical analysis.
• The parser uses the first components of the tokens
produced by the lexical analyzer to create a tree-like
intermediate representation that depicts the
grammatical structure of the token stream.
• The hierarchical tree structure generated in this phase
is called parse tree or syntax tree.
Figure : Syntax tree for position = initial + rate * 60
Semantic Analysis
• The semantic analyzer uses the syntax tree and the
information in the symbol table to check the source
program for semantic consistency with the language
definition.
• It ensures the correctness of the program, matching of
the parenthesis is also done in this phase.
• An important part of semantic analysis is type
checking, where the compiler checks that each
operator has matching operands.
• The compiler must report an error if a floating-point
number is used to index an array.
Semantic Analysis
Figure : Semantic tree for position = initial + rate * 60
Intermediate Code Generation
• After syntax and semantic analysis of the source program,
many compilers generate an explicit low-level or machine-
like intermediate representation
• The intermediate representation have two important
properties:
a. It should be easy to produce
b. It should be easy to translate into the target machine.
Three-address code is one of the intermediate representations,
which consists of a sequence of assembly-like instructions with
three operands per instruction.
Intermediate Code Generation
• Each operand can act like a register.
• The output of the intermediate code generator
consists of the three-address code sequence for
position = initial + rate * 60
• t1 = inttofloat(60)
• t2 = id3 * t1
• t3 = id2 + t2
• id1 = t3
Code Optimization
• The machine-independent code-optimization phase
attempts to improve the intermediate code so that better
target code will result. Usually better means faster.
• Optimization has to improve the efficiency of code so
that the target program running time and consumption
of memory can be reduced.
Moreover, t3 is used only once to transmit its value to id1 so
the optimizer can transform into the shorter sequence:
t1 = id3 * 60.0
id1 = id2 + t1
Code Generation
• The code generator takes as input an intermediate
representation of the source program and maps it
into the target language.
• If the target language is machine code, then the
registers or memory locations are selected for each
of the variables used by the program.
The intermediate instructions are translated into sequences of machine
instructions.
LDF R2, id3
MULF R2, R2 , #60.0
LDF Rl, id2
ADDF Rl, Rl, R2
STF idl, Rl
Figure : Translation of an
assignment statement
Symbol-Table Management
• The symbol table, which stores information about the
entire source program, is used by all phases of the
compiler.
• An essential function of a compiler is to record the
variable names used in the source program and collect
information about various attributes of each name.
• These attributes may provide information about the
storage allocated for a name, its type, its scope.
A symbol table can be implemented in one of the following ways:
Linear (sorted or unsorted) list
Binary Search Tree
Hash table
THE GROUPING OF PHASES
THE END

More Related Content

What's hot

Assembler design options
Assembler design optionsAssembler design options
Assembler design optionsMohd Arif
 
Lecture 01 introduction to compiler
Lecture 01 introduction to compilerLecture 01 introduction to compiler
Lecture 01 introduction to compilerIffat Anjum
 
Compiler Construction
Compiler ConstructionCompiler Construction
Compiler ConstructionAhmed Raza
 
Introduction of c programming unit-ii ppt
Introduction of  c programming unit-ii pptIntroduction of  c programming unit-ii ppt
Introduction of c programming unit-ii pptJStalinAsstProfessor
 
Programming Fundamental Presentation
Programming Fundamental PresentationProgramming Fundamental Presentation
Programming Fundamental Presentationfazli khaliq
 
Chap 1-language processor
Chap 1-language processorChap 1-language processor
Chap 1-language processorshindept123
 
Fundamentals of Language Processing
Fundamentals of Language ProcessingFundamentals of Language Processing
Fundamentals of Language ProcessingHemant Sharma
 
Single pass assembler
Single pass assemblerSingle pass assembler
Single pass assemblerBansari Shah
 
System software - macro expansion,nested macro calls
System software - macro expansion,nested macro callsSystem software - macro expansion,nested macro calls
System software - macro expansion,nested macro callsSARASWATHI S
 
Compiler Design
Compiler DesignCompiler Design
Compiler DesignMir Majid
 
Introduction to Compilers
Introduction to CompilersIntroduction to Compilers
Introduction to CompilersAkhil Kaushik
 

What's hot (20)

Assembler design options
Assembler design optionsAssembler design options
Assembler design options
 
Lecture 01 introduction to compiler
Lecture 01 introduction to compilerLecture 01 introduction to compiler
Lecture 01 introduction to compiler
 
Compiler Construction
Compiler ConstructionCompiler Construction
Compiler Construction
 
Linking in MS-Dos System
Linking in MS-Dos SystemLinking in MS-Dos System
Linking in MS-Dos System
 
Introduction of c programming unit-ii ppt
Introduction of  c programming unit-ii pptIntroduction of  c programming unit-ii ppt
Introduction of c programming unit-ii ppt
 
Programming Fundamental Presentation
Programming Fundamental PresentationProgramming Fundamental Presentation
Programming Fundamental Presentation
 
Chap 1-language processor
Chap 1-language processorChap 1-language processor
Chap 1-language processor
 
Fundamentals of Language Processing
Fundamentals of Language ProcessingFundamentals of Language Processing
Fundamentals of Language Processing
 
Single pass assembler
Single pass assemblerSingle pass assembler
Single pass assembler
 
Compiler design
Compiler designCompiler design
Compiler design
 
System software - macro expansion,nested macro calls
System software - macro expansion,nested macro callsSystem software - macro expansion,nested macro calls
System software - macro expansion,nested macro calls
 
Software tools
Software toolsSoftware tools
Software tools
 
1.Role lexical Analyzer
1.Role lexical Analyzer1.Role lexical Analyzer
1.Role lexical Analyzer
 
Introduction to Compiler
Introduction to CompilerIntroduction to Compiler
Introduction to Compiler
 
Loaders
LoadersLoaders
Loaders
 
Basic of compiler
Basic of compiler Basic of compiler
Basic of compiler
 
Compiler Design
Compiler DesignCompiler Design
Compiler Design
 
Types of Compilers
Types of CompilersTypes of Compilers
Types of Compilers
 
Introduction to Compilers
Introduction to CompilersIntroduction to Compilers
Introduction to Compilers
 
loaders and linkers
 loaders and linkers loaders and linkers
loaders and linkers
 

Similar to Introduction to Compiler Construction: Translators, Compilation, Interpretation and More

Compiler an overview
Compiler  an overviewCompiler  an overview
Compiler an overviewamudha arul
 
Chapter1pdf__2021_11_23_10_53_20.pdf
Chapter1pdf__2021_11_23_10_53_20.pdfChapter1pdf__2021_11_23_10_53_20.pdf
Chapter1pdf__2021_11_23_10_53_20.pdfDrIsikoIsaac
 
Compiler Design Introduction
Compiler Design Introduction Compiler Design Introduction
Compiler Design Introduction Thapar Institute
 
Phases of Compiler.pptx
Phases of Compiler.pptxPhases of Compiler.pptx
Phases of Compiler.pptxssuser3b4934
 
Pros and cons of c as a compiler language
  Pros and cons of c as a compiler language  Pros and cons of c as a compiler language
Pros and cons of c as a compiler languageAshok Raj
 
unit1pdf__2021_12_14_12_37_34.pdf
unit1pdf__2021_12_14_12_37_34.pdfunit1pdf__2021_12_14_12_37_34.pdf
unit1pdf__2021_12_14_12_37_34.pdfDrIsikoIsaac
 
Chapter-1.pptx compiler Design Course Material
Chapter-1.pptx compiler Design Course MaterialChapter-1.pptx compiler Design Course Material
Chapter-1.pptx compiler Design Course MaterialgadisaAdamu
 
2-Design Issues, Patterns, Lexemes, Tokens-28-04-2023.docx
2-Design Issues, Patterns, Lexemes, Tokens-28-04-2023.docx2-Design Issues, Patterns, Lexemes, Tokens-28-04-2023.docx
2-Design Issues, Patterns, Lexemes, Tokens-28-04-2023.docxvenkatapranaykumarGa
 
Introduction to Compiler Construction
Introduction to Compiler Construction Introduction to Compiler Construction
Introduction to Compiler Construction Sarmad Ali
 
basics of compiler design
basics of compiler designbasics of compiler design
basics of compiler designPreeti Katiyar
 
Dineshmaterial1 091225091539-phpapp02
Dineshmaterial1 091225091539-phpapp02Dineshmaterial1 091225091539-phpapp02
Dineshmaterial1 091225091539-phpapp02Tirumala Rao
 

Similar to Introduction to Compiler Construction: Translators, Compilation, Interpretation and More (20)

Compiler an overview
Compiler  an overviewCompiler  an overview
Compiler an overview
 
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
 
Chapter 1.pptx
Chapter 1.pptxChapter 1.pptx
Chapter 1.pptx
 
Compiler Design Introduction
Compiler Design Introduction Compiler Design Introduction
Compiler Design Introduction
 
Phases of Compiler.pptx
Phases of Compiler.pptxPhases of Compiler.pptx
Phases of Compiler.pptx
 
Pros and cons of c as a compiler language
  Pros and cons of c as a compiler language  Pros and cons of c as a compiler language
Pros and cons of c as a compiler language
 
Compiler Design
Compiler DesignCompiler Design
Compiler Design
 
unit1pdf__2021_12_14_12_37_34.pdf
unit1pdf__2021_12_14_12_37_34.pdfunit1pdf__2021_12_14_12_37_34.pdf
unit1pdf__2021_12_14_12_37_34.pdf
 
Phases of Compiler
Phases of CompilerPhases of Compiler
Phases of Compiler
 
The Phases of a Compiler
The Phases of a CompilerThe Phases of a Compiler
The Phases of a Compiler
 
Chapter-1.pptx compiler Design Course Material
Chapter-1.pptx compiler Design Course MaterialChapter-1.pptx compiler Design Course Material
Chapter-1.pptx compiler Design Course Material
 
2-Design Issues, Patterns, Lexemes, Tokens-28-04-2023.docx
2-Design Issues, Patterns, Lexemes, Tokens-28-04-2023.docx2-Design Issues, Patterns, Lexemes, Tokens-28-04-2023.docx
2-Design Issues, Patterns, Lexemes, Tokens-28-04-2023.docx
 
Chapter#01 cc
Chapter#01 ccChapter#01 cc
Chapter#01 cc
 
Compiler Design Material
Compiler Design MaterialCompiler Design Material
Compiler Design Material
 
COMPILER DESIGN PPTS.pptx
COMPILER DESIGN PPTS.pptxCOMPILER DESIGN PPTS.pptx
COMPILER DESIGN PPTS.pptx
 
Unit 1.pptx
Unit 1.pptxUnit 1.pptx
Unit 1.pptx
 
Introduction to Compiler Construction
Introduction to Compiler Construction Introduction to Compiler Construction
Introduction to Compiler Construction
 
Compiler
Compiler Compiler
Compiler
 
basics of compiler design
basics of compiler designbasics of compiler design
basics of compiler design
 
Dineshmaterial1 091225091539-phpapp02
Dineshmaterial1 091225091539-phpapp02Dineshmaterial1 091225091539-phpapp02
Dineshmaterial1 091225091539-phpapp02
 

Recently uploaded

HARMONY IN THE HUMAN BEING - Unit-II UHV-2
HARMONY IN THE HUMAN BEING - Unit-II UHV-2HARMONY IN THE HUMAN BEING - Unit-II UHV-2
HARMONY IN THE HUMAN BEING - Unit-II UHV-2RajaP95
 
Microscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxMicroscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxpurnimasatapathy1234
 
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Dr.Costas Sachpazis
 
Biology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxBiology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxDeepakSakkari2
 
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxDecoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxJoão Esperancinha
 
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...srsj9000
 
Internship report on mechanical engineering
Internship report on mechanical engineeringInternship report on mechanical engineering
Internship report on mechanical engineeringmalavadedarshan25
 
Call Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call GirlsCall Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call Girlsssuser7cb4ff
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCall Girls in Nagpur High Profile
 
main PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidmain PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidNikhilNagaraju
 
What are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxWhat are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxwendy cai
 
Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024hassan khalil
 
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escortsranjana rawat
 
IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024Mark Billinghurst
 
chaitra-1.pptx fake news detection using machine learning
chaitra-1.pptx  fake news detection using machine learningchaitra-1.pptx  fake news detection using machine learning
chaitra-1.pptx fake news detection using machine learningmisbanausheenparvam
 
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...Soham Mondal
 
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130Suhani Kapoor
 

Recently uploaded (20)

HARMONY IN THE HUMAN BEING - Unit-II UHV-2
HARMONY IN THE HUMAN BEING - Unit-II UHV-2HARMONY IN THE HUMAN BEING - Unit-II UHV-2
HARMONY IN THE HUMAN BEING - Unit-II UHV-2
 
Microscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxMicroscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptx
 
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptxExploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
 
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
 
Biology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxBiology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptx
 
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxDecoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
 
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
 
Internship report on mechanical engineering
Internship report on mechanical engineeringInternship report on mechanical engineering
Internship report on mechanical engineering
 
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCRCall Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
 
Call Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call GirlsCall Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call Girls
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
 
main PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidmain PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfid
 
What are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxWhat are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptx
 
Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024
 
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
 
IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024
 
chaitra-1.pptx fake news detection using machine learning
chaitra-1.pptx  fake news detection using machine learningchaitra-1.pptx  fake news detection using machine learning
chaitra-1.pptx fake news detection using machine learning
 
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
 
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
 

Introduction to Compiler Construction: Translators, Compilation, Interpretation and More

  • 1. Introduction to Compiler Construction Prof. A. N. Kazi Jawaharlal Darda Institute of Engineering & Technology, Yavatmal
  • 2. TRANSLATORS • A translator is one kind of program that takes one form of program (input) and converts into another form (output). The input program is called source language and the output program is called target language. Types of Translators are :: (1) Compilers (2) Interpreters (3) Assemblers
  • 3. COMPILATION AND INTERPRETATION • A compiler is a program that reads a program in one language and translates it into an equivalent program in another language. The translation done by a compiler is called compilation. • 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.
  • 4. COMPILATION AND INTERPRETATION  Compiler :  Interpreter :
  • 5. Compilers • “Compilation” – Translation of a program written in a source language into a semantically equivalent program written in a target language Compiler Error messages Source Program Target Program Input Output As an important role of a compiler is error showing to the programmer.
  • 6. INTERPRETER • An interpreter is a program that appears to execute a source program as if it were machine language. Fig: Execution in Interpreter Languages such as BASIC, SNOBOL, LISP can be translated using interpreters
  • 7. Compiler is a translator program that translates a program written in (HLL) the source program and translate it into an equivalent program in (MLL) the target program. Fig : Language Processing System HLL Consisting #include< > #define SIZE Pure HLL
  • 8. Fig : Structure of Compiler Fig : Execution process of source program in Compiler
  • 9. ASSEMBLER 1. Programmers found it difficult to write or read programs in machine language. They begin to use a mnemonic (symbols) for each machine instruction, which they would subsequently translate into machine language. 2. Such a mnemonic machine language is now called an assembly language.(ALP) 3. Programs known as assembler were written to automate the translation of assembly language in to machine language.
  • 10. LOADER AND LINK-EDITOR: • Loader : Once the assembler procedures an object program, that program must be placed into memory and executed. The assembler could place the object program directly in memory and transfer control to it, thereby causing the machine language program to be execute. • Linker : Add necessary library file that are included in source program
  • 11. LIST OF COMPILERS 1. Ada compilers 2 .ALGOL compilers 3 .BASIC compilers 4 .C# compilers 5 .C compilers 6 .C++ compilers 7 .COBOL compilers 8 .Common Lisp compilers 9. ECMAScript interpreters 10. Fortran compilers 11 .Java compilers 12. Pascal compilers 13. PL/I compilers 14. Python compilers 15. Smalltalk compilers
  • 12. Preprocessors, Compilers, Assemblers, and Linkers Preprocessor Compiler Assembler Linker Skeletal Source Program Source Program Target Assembly Program Relocatable Object Code Absolute Machine Code Libraries and Relocatable Object Files Try for example: gcc -v myprog.c
  • 13. Phases of a compiler
  • 14. • Lexical Analysis - The first phase of a compiler is called lexical analysis or scanning or linear analysis. The lexical analyzer reads the stream of characters making up the source program and groups the characters into meaningful sequences called lexemes. For each lexeme, the lexical analyzer produces output as a token of the form <token-name, attribute-value> The first component token-name is an abstract symbol that is used during syntax analysis, and the second component attribute-value points to an entry in the symbol table for this token.
  • 15. Lexeme mapped in Tokens 1) position is a lexeme that would be mapped into a token <id,1>. where , id is an abstract symbol standing for identifier and 1 points to the symbol able entry for position. (2) The assignment symbol = is a lexeme that is mapped into the token <=>. (3) initial is a lexeme that is mapped into the token <id, 2>. (4) + is a lexeme that is mapped into the token <+>. (5) rate is a lexeme that is mapped into the token <id, 3>. (6) * is a lexeme that is mapped into the token <*>. (7) 60 is a lexeme that is mapped into the token <60>. The sequence of tokens produced as follows after lexical analysis. <id, 1> <=> <id, 2> <+> <id, 3> <*> <60>
  • 16. Syntax Analysis • The second phase of the compiler is syntax analysis or parsing or hierarchical analysis. • The parser uses the first components of the tokens produced by the lexical analyzer to create a tree-like intermediate representation that depicts the grammatical structure of the token stream. • The hierarchical tree structure generated in this phase is called parse tree or syntax tree. Figure : Syntax tree for position = initial + rate * 60
  • 17. Semantic Analysis • The semantic analyzer uses the syntax tree and the information in the symbol table to check the source program for semantic consistency with the language definition. • It ensures the correctness of the program, matching of the parenthesis is also done in this phase. • An important part of semantic analysis is type checking, where the compiler checks that each operator has matching operands. • The compiler must report an error if a floating-point number is used to index an array.
  • 18. Semantic Analysis Figure : Semantic tree for position = initial + rate * 60
  • 19. Intermediate Code Generation • After syntax and semantic analysis of the source program, many compilers generate an explicit low-level or machine- like intermediate representation • The intermediate representation have two important properties: a. It should be easy to produce b. It should be easy to translate into the target machine. Three-address code is one of the intermediate representations, which consists of a sequence of assembly-like instructions with three operands per instruction.
  • 20. Intermediate Code Generation • Each operand can act like a register. • The output of the intermediate code generator consists of the three-address code sequence for position = initial + rate * 60 • t1 = inttofloat(60) • t2 = id3 * t1 • t3 = id2 + t2 • id1 = t3
  • 21. Code Optimization • The machine-independent code-optimization phase attempts to improve the intermediate code so that better target code will result. Usually better means faster. • Optimization has to improve the efficiency of code so that the target program running time and consumption of memory can be reduced. Moreover, t3 is used only once to transmit its value to id1 so the optimizer can transform into the shorter sequence: t1 = id3 * 60.0 id1 = id2 + t1
  • 22. Code Generation • The code generator takes as input an intermediate representation of the source program and maps it into the target language. • If the target language is machine code, then the registers or memory locations are selected for each of the variables used by the program. The intermediate instructions are translated into sequences of machine instructions. LDF R2, id3 MULF R2, R2 , #60.0 LDF Rl, id2 ADDF Rl, Rl, R2 STF idl, Rl
  • 23. Figure : Translation of an assignment statement
  • 24. Symbol-Table Management • The symbol table, which stores information about the entire source program, is used by all phases of the compiler. • An essential function of a compiler is to record the variable names used in the source program and collect information about various attributes of each name. • These attributes may provide information about the storage allocated for a name, its type, its scope. A symbol table can be implemented in one of the following ways: Linear (sorted or unsorted) list Binary Search Tree Hash table
  • 25. THE GROUPING OF PHASES