SlideShare a Scribd company logo
1 of 17
Air University, Multan Campus
A Faderally Charted Public Sector University

Introduction
Course: Compiler Construction
Tutor: Dr. Muhammad Sanaullah
muhammad.sanaullah@polito.it
Quotations
“If you don’t understand compilers, you can still write
programs – you can even be a competent
programmer – but you can’t be a master. ”



Hal Abelson, MIT

“If you don’t know how compilers work, then you
don’t know how computer work. If you’re not 100%
sure whether you know how compilers work, then
you don’t know how they work.”



Steve Yegge

2
Translator & Compiler
A translator or language processor is a program
that translate an input program written in a
programming language into an equivalent program in
another language.
Compiler is a type of translator, which takes a
program written in high-level programming language
as input (source program) and translates into an
equivalent program in low-level language (target
program), such as machine language or assembly
Source
Target
language.
Compiler





Program

3

Program
Compilers
Compilers traces the errors in the source program and
generates the error report.
 Every programming language have different compilers.
 Without compilation, no program written in a high-level
language can be executed.
 After compilation only the program in machine language
is loaded into the memory for execution.
 During execution, the target program is firstly loaded
into the memory and then the user interacts to generate
output.
Input supplied by
Output produced


the user
4

Compiler

after execution
Preprocessors
Before compilation, the source program is processed
by the preprocessor to prepare it for compilation.
The preprocessor program creates modified source
program from the original source program by
replacing the preprocessor directives with the
suitable content.
The modified source program act as an input to the
compiler.






5
Preprocessors
Preprocessor performs the following tasks:







It permits the user to include the header files in the
program and user can make use of the functions defined
in these header files.
It permits the user to include macros in the program.




Source
Program
6

Macros are the small set of instructions that are used in a
program respectively. Macros have two attributes: macro name
and macro definition.
Whenever the macro name is encountered in the program then
it is replaced by the macro definition (set of statements
correspond to the macro).
Preprocessor

Modified
Source
Program

Compiler

Target
Program
Interpreter
Interpreter directly executes the source program line
by line according to the given inputs.
Translation and execution of each statement are
carried out side by side. Thus, separate execution of
the program is not required.
The line by line execution of the program provides
better debugging environment than a compiler.






Source
Program
Interpreter
Input

7

Output
Compilers Vs Interpreter
The interpreter takes one statement then translates it and
executes it and then takes another statement. While the
compiler translates the entire program in one go and then
executes it.
Compiler generates the error report after the translation
of the entire page while an interpreter will stop the
translation after it gets the first error.
Compiler takes a larger amount of time in analyzing and
processing the high level language code comparatively
interpreter takes lesser time in the same process.
Besides the processing and analyzing time the overall
execution time of a code is faster for compiler relative to
the interpreter.









8
Compilers Vs Interpreter

9
Hybrid Compiler




Java language processors
combine compilation and
interpretation
To achieve faster
processing of inputs to
outputs, some java
compilers, called just-intime compilers, translate
the bytecodes into
machine language
immediately before they
run the intermediate
program to process the
input.

10

Source
Program

Translator

Compiler

ByteCodes
Intermediate
Program
Input

Interpreter
Virtual
Machine

Output
Assemblers


In some cases, compiler generates the target
program in assembly language, and then this
intermediate (assembly program – Mnemonics) is
passed to assembler which convert it into machine
code.

Source
Program

11

Compiler

Assembly
Language
Program

Assembler

Machine
Language
Code
Analysis of a Source Program
Some time, a source program may be divided into
modules stored in separate files.
 The task for collecting the source program (or
macros) from separate files is called preprocessor.
 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 program is then fed to
assembler that produces relocatable machine code
12
as its output.

Analysis of a Source Program






Larger programs are often compiled in pieces, so the
relocatable machine code may have to be linked
together with other relacateble 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.

13
Analysis of a Source Program
Source Program
Preprocessor
Modified Source Program
Compiler
If target program is in machine language
then it execute directly

If target program is in assembly language
then it passed to assembler

Assembler
Relocatable Machine Code
Linker/loader

Target Machine Code
14

Library Files and
Relocatable Object Files
References





A. V. Aho, Compilers: principles, techniques, and
tools, Pearson Education India, 2007.
ITL Education Solutions Limited, Principles of
compiler design, Dorling Kindersley (India) Pvt.
Ltd, Pearson Education in South Asia, 2012.
P.H. Dave, H.B. Dave, Compilers: Principles and
Practice, Dorling Kindersley (India) Pvt. Ltd, Pearson
Education in South Asia, 2012.

15
16

Design Time Methodology for the Formal Modeling and Verification of Smart Environments
Compiler Construction Course - Introduction

More Related Content

What's hot (20)

Compiler Construction
Compiler ConstructionCompiler Construction
Compiler Construction
 
Compilers
CompilersCompilers
Compilers
 
Language translator
Language translatorLanguage translator
Language translator
 
Phases of a Compiler
Phases of a CompilerPhases of a Compiler
Phases of a Compiler
 
Interpreter
InterpreterInterpreter
Interpreter
 
Compilers
CompilersCompilers
Compilers
 
what is compiler and five phases of compiler
what is compiler and five phases of compilerwhat is compiler and five phases of compiler
what is compiler and five phases of compiler
 
Principles of programming languages. Detail notes
Principles of programming languages. Detail notesPrinciples of programming languages. Detail notes
Principles of programming languages. Detail notes
 
Introduction to Compiler
Introduction to CompilerIntroduction to Compiler
Introduction to Compiler
 
Assembler
AssemblerAssembler
Assembler
 
Life cycle of a computer program
Life cycle of a computer programLife cycle of a computer program
Life cycle of a computer program
 
Finite Automata
Finite AutomataFinite Automata
Finite Automata
 
Compiler Construction | Lecture 1 | What is a compiler?
Compiler Construction | Lecture 1 | What is a compiler?Compiler Construction | Lecture 1 | What is a compiler?
Compiler Construction | Lecture 1 | What is a compiler?
 
System Programming Overview
System Programming OverviewSystem Programming Overview
System Programming Overview
 
Syntax analysis
Syntax analysisSyntax analysis
Syntax analysis
 
Compiler vs interpreter
Compiler vs interpreterCompiler vs interpreter
Compiler vs interpreter
 
Phases of compiler
Phases of compilerPhases of compiler
Phases of compiler
 
Introduction to .NET Framework
Introduction to .NET FrameworkIntroduction to .NET Framework
Introduction to .NET Framework
 
Compilers
CompilersCompilers
Compilers
 
Programming Fundamentals lecture 1
Programming Fundamentals lecture 1Programming Fundamentals lecture 1
Programming Fundamentals lecture 1
 

Viewers also liked

Compiler Design
Compiler DesignCompiler Design
Compiler DesignMir Majid
 
Phases of the Compiler - Systems Programming
Phases of the Compiler - Systems ProgrammingPhases of the Compiler - Systems Programming
Phases of the Compiler - Systems ProgrammingMukesh Tekwani
 
Introduction to compiler construction
Introduction to compiler constructionIntroduction to compiler construction
Introduction to compiler constructionYuji Shimojo
 
Introduction to data structure
Introduction to data structureIntroduction to data structure
Introduction to data structureZaid Shabbir
 
Compiler Construction
Compiler ConstructionCompiler Construction
Compiler ConstructionSarmad Ali
 
Assesing speaking skills
Assesing speaking skillsAssesing speaking skills
Assesing speaking skillssyed ahmed
 
Introduction to Data structure & Algorithms - Sethuonline.com | Sathyabama Un...
Introduction to Data structure & Algorithms - Sethuonline.com | Sathyabama Un...Introduction to Data structure & Algorithms - Sethuonline.com | Sathyabama Un...
Introduction to Data structure & Algorithms - Sethuonline.com | Sathyabama Un...sethuraman R
 
7 compiler lab
7 compiler lab 7 compiler lab
7 compiler lab MashaelQ
 
Compiler Design - Introduction to Compiler
Compiler Design - Introduction to CompilerCompiler Design - Introduction to Compiler
Compiler Design - Introduction to CompilerIffat Anjum
 
Compiler Design Basics
Compiler Design BasicsCompiler Design Basics
Compiler Design BasicsAkhil Kaushik
 
Intro to Buses (Computer Architecture)
Intro to Buses  (Computer Architecture)Intro to Buses  (Computer Architecture)
Intro to Buses (Computer Architecture)Matthew Levandowski
 
Compiler Design(NANTHU NOTES)
Compiler Design(NANTHU NOTES)Compiler Design(NANTHU NOTES)
Compiler Design(NANTHU NOTES)guest251d9a
 

Viewers also liked (19)

Compiler Chapter 1
Compiler Chapter 1Compiler Chapter 1
Compiler Chapter 1
 
Compiler Design
Compiler DesignCompiler Design
Compiler Design
 
Phases of the Compiler - Systems Programming
Phases of the Compiler - Systems ProgrammingPhases of the Compiler - Systems Programming
Phases of the Compiler - Systems Programming
 
Lexical analyzer
Lexical analyzerLexical analyzer
Lexical analyzer
 
Buses
BusesBuses
Buses
 
Part of speech
Part of speechPart of speech
Part of speech
 
Introduction to compiler construction
Introduction to compiler constructionIntroduction to compiler construction
Introduction to compiler construction
 
Introduction to data structure
Introduction to data structureIntroduction to data structure
Introduction to data structure
 
Compiler Construction
Compiler ConstructionCompiler Construction
Compiler Construction
 
Assesing speaking skills
Assesing speaking skillsAssesing speaking skills
Assesing speaking skills
 
Introduction to Data structure & Algorithms - Sethuonline.com | Sathyabama Un...
Introduction to Data structure & Algorithms - Sethuonline.com | Sathyabama Un...Introduction to Data structure & Algorithms - Sethuonline.com | Sathyabama Un...
Introduction to Data structure & Algorithms - Sethuonline.com | Sathyabama Un...
 
Compiler construction
Compiler constructionCompiler construction
Compiler construction
 
7 compiler lab
7 compiler lab 7 compiler lab
7 compiler lab
 
Lex
LexLex
Lex
 
Compiler Design - Introduction to Compiler
Compiler Design - Introduction to CompilerCompiler Design - Introduction to Compiler
Compiler Design - Introduction to Compiler
 
Compiler Design Basics
Compiler Design BasicsCompiler Design Basics
Compiler Design Basics
 
Intro to Buses (Computer Architecture)
Intro to Buses  (Computer Architecture)Intro to Buses  (Computer Architecture)
Intro to Buses (Computer Architecture)
 
Lexical analyzer
Lexical analyzerLexical analyzer
Lexical analyzer
 
Compiler Design(NANTHU NOTES)
Compiler Design(NANTHU NOTES)Compiler Design(NANTHU NOTES)
Compiler Design(NANTHU NOTES)
 

Similar to Compiler Construction Course - Introduction

Introduction to compiler
Introduction to compilerIntroduction to compiler
Introduction to compilerA. S. M. Shafi
 
Compliers and interpreters
Compliers and interpretersCompliers and interpreters
Compliers and interpretersshivasdhtsvmic
 
Chapter 2 Program language translation.pptx
Chapter 2 Program language translation.pptxChapter 2 Program language translation.pptx
Chapter 2 Program language translation.pptxdawod yimer
 
La 5 Pl Translator
La 5   Pl TranslatorLa 5   Pl Translator
La 5 Pl TranslatorCma Mohd
 
design intoduction of_COMPILER_DESIGN.pdf
design intoduction of_COMPILER_DESIGN.pdfdesign intoduction of_COMPILER_DESIGN.pdf
design intoduction of_COMPILER_DESIGN.pdfadvRajatSharma
 
Language processing system.pdf
Language processing system.pdfLanguage processing system.pdf
Language processing system.pdfRakibRahman19
 
Introduction to system programming
Introduction to system programmingIntroduction to system programming
Introduction to system programmingsonalikharade3
 
COMPILER DESIGN OPTIONS
COMPILER DESIGN OPTIONSCOMPILER DESIGN OPTIONS
COMPILER DESIGN OPTIONSsonalikharade3
 
compilervsinterpreter-161008074915.pdf
compilervsinterpreter-161008074915.pdfcompilervsinterpreter-161008074915.pdf
compilervsinterpreter-161008074915.pdfHarshaVardhan196987
 
FIT-Unit3 chapter2- Computer Languages
FIT-Unit3 chapter2- Computer LanguagesFIT-Unit3 chapter2- Computer Languages
FIT-Unit3 chapter2- Computer Languagesraksharao
 
SSD Mod 2 -18CS61_Notes.pdf
SSD Mod 2 -18CS61_Notes.pdfSSD Mod 2 -18CS61_Notes.pdf
SSD Mod 2 -18CS61_Notes.pdfJacobDragonette
 
Introduction to systems programming
Introduction to systems programmingIntroduction to systems programming
Introduction to systems programmingMukesh Tekwani
 
Linker and Loader Explained
Linker and Loader  ExplainedLinker and Loader  Explained
Linker and Loader ExplainedAdarsh Kr Sinha
 
[ITP - Lecture 01] Introduction to Programming & Different Programming Languages
[ITP - Lecture 01] Introduction to Programming & Different Programming Languages[ITP - Lecture 01] Introduction to Programming & Different Programming Languages
[ITP - Lecture 01] Introduction to Programming & Different Programming LanguagesMuhammad Hammad Waseem
 
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
 

Similar to Compiler Construction Course - Introduction (20)

COMPILER DESIGN.docx
COMPILER DESIGN.docxCOMPILER DESIGN.docx
COMPILER DESIGN.docx
 
Introduction to compiler
Introduction to compilerIntroduction to compiler
Introduction to compiler
 
Compliers and interpreters
Compliers and interpretersCompliers and interpreters
Compliers and interpreters
 
Lect-01.ppt
Lect-01.pptLect-01.ppt
Lect-01.ppt
 
Chapter 2 Program language translation.pptx
Chapter 2 Program language translation.pptxChapter 2 Program language translation.pptx
Chapter 2 Program language translation.pptx
 
La 5 Pl Translator
La 5   Pl TranslatorLa 5   Pl Translator
La 5 Pl Translator
 
design intoduction of_COMPILER_DESIGN.pdf
design intoduction of_COMPILER_DESIGN.pdfdesign intoduction of_COMPILER_DESIGN.pdf
design intoduction of_COMPILER_DESIGN.pdf
 
Assembler
AssemblerAssembler
Assembler
 
Language processing system.pdf
Language processing system.pdfLanguage processing system.pdf
Language processing system.pdf
 
Introduction to system programming
Introduction to system programmingIntroduction to system programming
Introduction to system programming
 
COMPILER DESIGN OPTIONS
COMPILER DESIGN OPTIONSCOMPILER DESIGN OPTIONS
COMPILER DESIGN OPTIONS
 
compilervsinterpreter-161008074915.pdf
compilervsinterpreter-161008074915.pdfcompilervsinterpreter-161008074915.pdf
compilervsinterpreter-161008074915.pdf
 
FIT-Unit3 chapter2- Computer Languages
FIT-Unit3 chapter2- Computer LanguagesFIT-Unit3 chapter2- Computer Languages
FIT-Unit3 chapter2- Computer Languages
 
SSD Mod 2 -18CS61_Notes.pdf
SSD Mod 2 -18CS61_Notes.pdfSSD Mod 2 -18CS61_Notes.pdf
SSD Mod 2 -18CS61_Notes.pdf
 
Introduction to systems programming
Introduction to systems programmingIntroduction to systems programming
Introduction to systems programming
 
Compiler vs interpreter
Compiler vs interpreter Compiler vs interpreter
Compiler vs interpreter
 
Linker and Loader Explained
Linker and Loader  ExplainedLinker and Loader  Explained
Linker and Loader Explained
 
Translators(Compiler, Assembler) and interpreter
Translators(Compiler, Assembler) and interpreterTranslators(Compiler, Assembler) and interpreter
Translators(Compiler, Assembler) and interpreter
 
[ITP - Lecture 01] Introduction to Programming & Different Programming Languages
[ITP - Lecture 01] Introduction to Programming & Different Programming Languages[ITP - Lecture 01] Introduction to Programming & Different Programming Languages
[ITP - Lecture 01] Introduction to Programming & Different Programming Languages
 
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
 

Recently uploaded

MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxMULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxAnupkumar Sharma
 
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITYISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITYKayeClaireEstoconing
 
ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4MiaBumagat1
 
How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17Celine George
 
Q4 English4 Week3 PPT Melcnmg-based.pptx
Q4 English4 Week3 PPT Melcnmg-based.pptxQ4 English4 Week3 PPT Melcnmg-based.pptx
Q4 English4 Week3 PPT Melcnmg-based.pptxnelietumpap1
 
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...JhezDiaz1
 
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxINTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxHumphrey A Beña
 
4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptxmary850239
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxiammrhaywood
 
Barangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptxBarangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptxCarlos105
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatYousafMalik24
 
Keynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designKeynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designMIPLM
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSGRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSJoshuaGantuangco2
 
How to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPHow to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPCeline George
 
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)lakshayb543
 
Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Celine George
 
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfAMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfphamnguyenenglishnb
 

Recently uploaded (20)

MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxMULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
 
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITYISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
 
ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4
 
How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17
 
Q4 English4 Week3 PPT Melcnmg-based.pptx
Q4 English4 Week3 PPT Melcnmg-based.pptxQ4 English4 Week3 PPT Melcnmg-based.pptx
Q4 English4 Week3 PPT Melcnmg-based.pptx
 
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
 
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxINTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
 
4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
 
Barangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptxBarangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptx
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice great
 
Keynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designKeynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-design
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSGRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
 
How to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPHow to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERP
 
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
 
Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17
 
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfAMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
 
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptxLEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
 
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptxYOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
 

Compiler Construction Course - Introduction

  • 1. Air University, Multan Campus A Faderally Charted Public Sector University Introduction Course: Compiler Construction Tutor: Dr. Muhammad Sanaullah muhammad.sanaullah@polito.it
  • 2. Quotations “If you don’t understand compilers, you can still write programs – you can even be a competent programmer – but you can’t be a master. ”  Hal Abelson, MIT “If you don’t know how compilers work, then you don’t know how computer work. If you’re not 100% sure whether you know how compilers work, then you don’t know how they work.”  Steve Yegge 2
  • 3. Translator & Compiler A translator or language processor is a program that translate an input program written in a programming language into an equivalent program in another language. Compiler is a type of translator, which takes a program written in high-level programming language as input (source program) and translates into an equivalent program in low-level language (target program), such as machine language or assembly Source Target language. Compiler   Program 3 Program
  • 4. Compilers Compilers traces the errors in the source program and generates the error report.  Every programming language have different compilers.  Without compilation, no program written in a high-level language can be executed.  After compilation only the program in machine language is loaded into the memory for execution.  During execution, the target program is firstly loaded into the memory and then the user interacts to generate output. Input supplied by Output produced  the user 4 Compiler after execution
  • 5. Preprocessors Before compilation, the source program is processed by the preprocessor to prepare it for compilation. The preprocessor program creates modified source program from the original source program by replacing the preprocessor directives with the suitable content. The modified source program act as an input to the compiler.    5
  • 6. Preprocessors Preprocessor performs the following tasks:    It permits the user to include the header files in the program and user can make use of the functions defined in these header files. It permits the user to include macros in the program.   Source Program 6 Macros are the small set of instructions that are used in a program respectively. Macros have two attributes: macro name and macro definition. Whenever the macro name is encountered in the program then it is replaced by the macro definition (set of statements correspond to the macro). Preprocessor Modified Source Program Compiler Target Program
  • 7. Interpreter Interpreter directly executes the source program line by line according to the given inputs. Translation and execution of each statement are carried out side by side. Thus, separate execution of the program is not required. The line by line execution of the program provides better debugging environment than a compiler.    Source Program Interpreter Input 7 Output
  • 8. Compilers Vs Interpreter The interpreter takes one statement then translates it and executes it and then takes another statement. While the compiler translates the entire program in one go and then executes it. Compiler generates the error report after the translation of the entire page while an interpreter will stop the translation after it gets the first error. Compiler takes a larger amount of time in analyzing and processing the high level language code comparatively interpreter takes lesser time in the same process. Besides the processing and analyzing time the overall execution time of a code is faster for compiler relative to the interpreter.     8
  • 10. Hybrid Compiler   Java language processors combine compilation and interpretation To achieve faster processing of inputs to outputs, some java compilers, called just-intime compilers, translate the bytecodes into machine language immediately before they run the intermediate program to process the input. 10 Source Program Translator Compiler ByteCodes Intermediate Program Input Interpreter Virtual Machine Output
  • 11. Assemblers  In some cases, compiler generates the target program in assembly language, and then this intermediate (assembly program – Mnemonics) is passed to assembler which convert it into machine code. Source Program 11 Compiler Assembly Language Program Assembler Machine Language Code
  • 12. Analysis of a Source Program Some time, a source program may be divided into modules stored in separate files.  The task for collecting the source program (or macros) from separate files is called preprocessor.  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 program is then fed to assembler that produces relocatable machine code 12 as its output. 
  • 13. Analysis of a Source Program    Larger programs are often compiled in pieces, so the relocatable machine code may have to be linked together with other relacateble 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. 13
  • 14. Analysis of a Source Program Source Program Preprocessor Modified Source Program Compiler If target program is in machine language then it execute directly If target program is in assembly language then it passed to assembler Assembler Relocatable Machine Code Linker/loader Target Machine Code 14 Library Files and Relocatable Object Files
  • 15. References    A. V. Aho, Compilers: principles, techniques, and tools, Pearson Education India, 2007. ITL Education Solutions Limited, Principles of compiler design, Dorling Kindersley (India) Pvt. Ltd, Pearson Education in South Asia, 2012. P.H. Dave, H.B. Dave, Compilers: Principles and Practice, Dorling Kindersley (India) Pvt. Ltd, Pearson Education in South Asia, 2012. 15
  • 16. 16 Design Time Methodology for the Formal Modeling and Verification of Smart Environments