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 | 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?
 
Computer Language Translator
Computer Language TranslatorComputer Language Translator
Computer Language Translator
 
Introduction to Compiler
Introduction to CompilerIntroduction to Compiler
Introduction to Compiler
 
Introduction to systems programming
Introduction to systems programmingIntroduction to systems programming
Introduction to systems programming
 
Introduction to compiler
Introduction to compilerIntroduction to compiler
Introduction to compiler
 
Introduction to Compiler design
Introduction to Compiler design Introduction to Compiler design
Introduction to Compiler design
 
Language processor
Language processorLanguage processor
Language processor
 
COMPILER DESIGN OPTIONS
COMPILER DESIGN OPTIONSCOMPILER DESIGN OPTIONS
COMPILER DESIGN OPTIONS
 
Phases of a Compiler
Phases of a CompilerPhases of a Compiler
Phases of a Compiler
 
Software tools
Software toolsSoftware tools
Software tools
 
System programming note
System programming noteSystem programming note
System programming note
 
Advanced Software Engineering.ppt
Advanced Software Engineering.pptAdvanced Software Engineering.ppt
Advanced Software Engineering.ppt
 
Language processing activity
Language processing activityLanguage processing activity
Language processing activity
 
Interpreter
InterpreterInterpreter
Interpreter
 
Fundamentals of Language Processing
Fundamentals of Language ProcessingFundamentals of Language Processing
Fundamentals of Language Processing
 
Compiler Design Basics
Compiler Design BasicsCompiler Design Basics
Compiler Design Basics
 
Introduction to Computer Programming
Introduction to Computer ProgrammingIntroduction to Computer Programming
Introduction to Computer Programming
 
extreme Programming
extreme Programmingextreme Programming
extreme Programming
 
Compiler construction
Compiler constructionCompiler construction
Compiler construction
 
Linker and Loader Explained
Linker and Loader  ExplainedLinker and Loader  Explained
Linker and Loader Explained
 

Viewers also liked

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 compileradilmehmood93
 
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
 
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 (18)

Compiler Construction
Compiler ConstructionCompiler Construction
Compiler Construction
 
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
 
Compilers
CompilersCompilers
Compilers
 
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...
 
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
 
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
 
compilervsinterpreter-161008074915.pdf
compilervsinterpreter-161008074915.pdfcompilervsinterpreter-161008074915.pdf
compilervsinterpreter-161008074915.pdfHarshaVardhan196987
 
Compiler vs interpreter
Compiler vs interpreterCompiler vs interpreter
Compiler vs interpreterParas Patel
 
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
 
[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
 
compilervsinterpreter-161008074915.pdf
compilervsinterpreter-161008074915.pdfcompilervsinterpreter-161008074915.pdf
compilervsinterpreter-161008074915.pdf
 
Compiler vs interpreter
Compiler vs interpreterCompiler vs interpreter
Compiler vs interpreter
 
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
 
Compiler vs interpreter
Compiler vs interpreter Compiler vs interpreter
Compiler vs interpreter
 
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
 
linkerloader ss-2.pptx
linkerloader ss-2.pptxlinkerloader ss-2.pptx
linkerloader ss-2.pptx
 
SYSTEM DEVELOPMENT
SYSTEM DEVELOPMENTSYSTEM DEVELOPMENT
SYSTEM DEVELOPMENT
 

Recently uploaded

Choosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for ParentsChoosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for Parentsnavabharathschool99
 
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
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPCeline George
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersSabitha Banu
 
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
 
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...Postal Advocate Inc.
 
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17Celine George
 
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...Nguyen Thanh Tu Collection
 
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
 
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
 
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
 
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
 
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
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceSamikshaHamane
 
Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Mark Reed
 
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
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Celine George
 
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
 

Recently uploaded (20)

Choosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for ParentsChoosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for Parents
 
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
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERP
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginners
 
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
 
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
 
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
 
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
 
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
 
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...
 
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 🔝✔️✔️
 
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
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in Pharmacovigilance
 
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
 
Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)
 
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
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17
 
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
 

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