SlideShare a Scribd company logo
1 of 48
COMPILER DESIGN
By:
Akhil Kaushik,
Asstt. Prof. T.I.T&S Bhiwani
Table of Contents
• Introduction.
• History.
• Why study Compiler?
• Translators.
• Structure of Compiler.
• Compiler Construction Tools.
Introduction
• A compiler is a computer program (or
set of programs) that transforms
source code written in a high level
language (the source language) into
low level language (the target
language may be assembly language
or machine language (0.1)).
Introduction
Source Language Target Language
Introduction
Compiler basically does two things:
• Analysis: Compiling source code &
detecting errors in it.
• Synthesis: Translating the source
code into object code depending
upon the type of machine.
Introduction
• Program errors are difficult to track if
the compiler is wrongly designed.
• Hence compiler construction is a very
tedious and long process.
Introduction
• One-pass compiler: It compiles the that
passes through the source code of each
compilation unit only once.
• They are faster than multi-pass compiler.
• Their efficiency is limited because they
don’t produce intermediate codes which
can be refined easily.
• Also known as ‘Narrow Compiler’.
Introduction
• Multi-pass compiler: It processes the
source code or abstract syntax tree of a
program several times.
• It may create one or more intermediate
codes (easy to refine).
• Each pass takes output of previous phase
as input; hence requires less memory.
• Also known as ‘Wide Compiler’.
History
• Software for early computers were
written in assembly language.
• The need of reusability of code gave
birth to programming languages.
• This need grow huge to overcome
the cost restriction of compiler.
History
• The concept of machine independent
programming gave birth to the need
of compilers in 1950s.
• The 1st
compiler was written by Grace
Hopper in 1952 for A-0 programming
language.
History
• The 1st
complete compiler was
developed by FORTRAN team lead
by John Backus @ IBM in 1957.
• COBOL was the 1st
language to be
compiled on multiple platforms in
1960.
History
• Earlier compilers were written in
assembly languages.
• The 1st
compiler in HLL was created
for LISP by Tim Hart & Mike Levin @
MIT, USA in 1962, which was a self-
hosting Compiler.
History
• Most compilers are made in C or
Pascal languages.
• However the trend is changing to
self-hosting compilers, which can
compile the source code of the same
language in which they are created.
Why Study Compiler?
• Its essential to understand the heart
of programming by computer
engineering students.
• There may be need of designing a
compiler for any software language in
the profession.
Why Study Compiler?
• Increases understanding of language
semantics.
• Helps to handle language performance
issues.
• Opportunity for non-trivial programming
project
Translators
• It is important to understand that
compiler is a kind of translator, which
translates high level language
(human understandable) to low-level
language(machine understandable).
Translators
• Interpreter: This software converts the
high-level language into low-level
language line by line.
• It takes less memory than compiler.
• It takes more time than compiler.
• It is more efficient in error detection than
compiler.
• It takes more time to build.
Translators
• Assembler: This software converts
the assembly language (assembly
instruction mnemonics) into machine
level language (opcodes i.e.0,1).
• It offers reusability of assembly codes
on different machine platforms.
Translators
• Cross-Compiler: If the compiled
program can run on a computer
whose C.P.U or O.S is different from
the one on which the compiler runs,
the compiler is known as a cross-
complier.
Translators
• Language Translator / Source to
source translator / Language
Converter: It converts programs in
one high-level language to another
high-level language.
• Ex: From Java code to ASP.Net code
Translators
• Language Rewriter: It is a program
that changes form of expression of
the same language.
• It does not changes the language of
source code.
Translators
• Decompiler: It is a piece of software
that converts the low-level language
to high-level language .
• It is not as famous, but may prove a
useful tool sometimes.
Translators
• Compiler-Compiler: It is a tool that
creates a compiler, interpreter or
parser from the information provided
on formal description of any
language.
• The earliest & most common type is
parser-generator.
Translators
• Linker: It is a program that combines
object modules(object programs) to
form executable program.
• Each module of software is compiled
separately to produce object programs.
• Linker will combine all object modules &
give it to loader for loading it in memory.
Translators
• Loader: It is a program which accepts
input as linked modules & loads them into
main memory for execution.
• It copies modules from secondary memory
to main memory.
• It may also replace virtual addresses with
physical addresses.
• Linker & Loader may overlap.
Structure of Compiler
• Compilers bridge the gap b/w high level
language & machine hardware.
• Compiler requires:
1. Finding errors in syntax of program.
2. Generating correct & efficient object code.
3. Run-time organization.
4. Formatting o/p acc. to linker/ assembler.
Structure of Compiler
Structure of Compiler
Compilation- Front End
(also known as Analysis Part)
• Lexical Analysis
• Syntax Analysis
• Semantic Analysis
• Intermediate Code Generation
* => Front end is machine independent.
Structure of Compiler
Compilation- Front End
• Determines operations implied by the
source program which are recorded in a
tree structure called the Syntax Tree.
• Breaks up the source code into basic
pieces, while storing info. in the symbol
table
Structure of Compiler
Compilation- Back End
(also known as Synthesis Part )
• Code Optimization
• Code Generation
* => Back end is machine dependent.
Structure of Compiler
Compilation- Back End
• Constructs the target code from the
syntax tree, and from the information in
the symbol table.
• Here, code optimization offers efficiency
of code generation with least use of
resources.
Structure of Compiler
Lexical Analysis
• Initial part of reading and analyzing the
program text.
• Text is read and divided into tokens, each
of which corresponds to a symbol in the
programming language.
• Ex: Variable, keyword, delimiters or digits.
Structure of Compiler
Lexical Analysis
Ex: a = b + 5 – (c * d)
Token Type Value
Identifier a, b, c, d
Operator +, -, *
Constant 5
Delimiter (, )
Structure of Compiler
Syntax Analysis
• It takes list of tokens produced by
lexical analysis.
• Then, these tokens are arranged in a
tree like structure (Syntax tree), which
reflects program structure.
• Also known as Parsing.
Structure of Compiler
Semantic Analysis
• It validates the syntax tree by applying
rules & regulations of the target language.
• It does type checking, scope resolution,
variable declaration, etc.
• It decorates the syntax tree by putting data
types, values, etc.
Structure of Compiler
Intermediate Code Generation
• The program is translated to a simple
machine independent intermediate
language.
• Register allocation of variables is
done in this phase.
Structure of Compiler
Code Optimization
• It aims to reduce process timings of
any program.
• It produces efficient programming
code.
• It is an optional phase.
Structure of Compiler
Code Optimization
• Removing unreachable code.
• Getting rid of unused variables
• Eliminating multiplication by 1 and addition
by 0
• Removing statements that are not modified
from the loop
• Common sub-expression elimination.
Structure of Compiler
Code Generation
• Target program is generated in the machine
language of the target architecture.
• Memory locations are selected for each
variable.
• Instructions are chosen for each operation
• Individual tree nodes are translated into
sequence of m/c language instructions.
Structure of Compiler
Symbol Table
• It stores identifiers identified in lexical
analysis.
• It adds type and scope information during
syntactical and semantical analysis.
• Also used for ‘Live analysis’ in optimization.
• This info is used in code generation to find
which instructions to use.
Structure of Compiler
Error Handler
• It handles error handling & reporting during
many phases.
• Ex: Invalid character sequence in scanning,
invalid token sequences in parsing, type &
scope errors in semantic analysis.
Compiler Construction Tools
• Compiler construction tools were introduced
after widespread of computers.
• Also known as compiler- compilers, compiler-
generators or translator writing systems.
• These tools may use sophisticated algo. or
specified languages for specifying &
implementing the component.
Compiler Construction Tools
• Scanner Generators: These generate lexical
analyzers.
• The basic lexical analyzer is produced by
Finite Automata, which takes input in form of
regular expressions.
• Ex: LEX for Unix O.S.
Compiler Construction Tools
• Parser Generators: These software produce
syntax analyzers which takes input based on
context-free grammar.
• Earlier, used to be most difficult to develop
but now, easier to develop & implement.
Compiler Construction Tools
• Syntax-directed Translation Engines: These
s/w products produce intermediate code with
the help of parse tree.
• Main idea is associating 1 or more translations
with each node of parse tree.
• Each node is defined in terms of translations
at its neighboring nodes in the tree.
Compiler Construction Tools
• Automatic Code Generator: This software
basically take intermediate code as input &
produce machine language as output.
• It is capable of fetching data from various
storage locations like registers, static memory,
stack, etc.
• Basic technique here is ‘template matching’.
Compiler Construction Tools
• Data Flow Engines: It is a tool used for code
optimization.
• Info is supplied by user & intermediate code is
compared to analyze the relation.
• It also does data-flow analysis i.e. finding out
how values are transmitted from one part to
another part of the program.
Further Contact Details
For any queries, please contact me at:
akhil1681@gmail.com
Or
http://akhil1681.blogspot.com

More Related Content

What's hot

What's hot (20)

Compiler construction tools
Compiler construction toolsCompiler construction tools
Compiler construction tools
 
Single pass assembler
Single pass assemblerSingle pass assembler
Single pass assembler
 
Compiler Design(NANTHU NOTES)
Compiler Design(NANTHU NOTES)Compiler Design(NANTHU NOTES)
Compiler Design(NANTHU NOTES)
 
Parsing
ParsingParsing
Parsing
 
Syntax Analysis in Compiler Design
Syntax Analysis in Compiler Design Syntax Analysis in Compiler Design
Syntax Analysis in Compiler Design
 
Compiler Design Unit 1
Compiler Design Unit 1Compiler Design Unit 1
Compiler Design Unit 1
 
COMPILER DESIGN
COMPILER DESIGNCOMPILER DESIGN
COMPILER DESIGN
 
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
 
Introduction to Compiler Construction
Introduction to Compiler Construction Introduction to Compiler Construction
Introduction to Compiler Construction
 
System Programming Overview
System Programming OverviewSystem Programming Overview
System Programming Overview
 
Lexical analysis - Compiler Design
Lexical analysis - Compiler DesignLexical analysis - Compiler Design
Lexical analysis - Compiler Design
 
Phases of compiler
Phases of compilerPhases of compiler
Phases of compiler
 
Type checking compiler construction Chapter #6
Type checking compiler construction Chapter #6Type checking compiler construction Chapter #6
Type checking compiler construction Chapter #6
 
Compiler Construction
Compiler ConstructionCompiler Construction
Compiler Construction
 
Lexical Analysis
Lexical AnalysisLexical Analysis
Lexical Analysis
 
32 dynamic linking nd overlays
32 dynamic linking nd overlays32 dynamic linking nd overlays
32 dynamic linking nd overlays
 
Lexical Analysis - Compiler Design
Lexical Analysis - Compiler DesignLexical Analysis - Compiler Design
Lexical Analysis - Compiler Design
 
1.Role lexical Analyzer
1.Role lexical Analyzer1.Role lexical Analyzer
1.Role lexical Analyzer
 
Phases of a Compiler
Phases of a CompilerPhases of a Compiler
Phases of a Compiler
 
Introduction to Compiler
Introduction to CompilerIntroduction to Compiler
Introduction to Compiler
 

Viewers also liked

Compiler Design - Introduction to Compiler
Compiler Design - Introduction to CompilerCompiler Design - Introduction to Compiler
Compiler Design - Introduction to CompilerIffat Anjum
 
Compiler vs Interpreter-Compiler design ppt.
Compiler vs Interpreter-Compiler design ppt.Compiler vs Interpreter-Compiler design ppt.
Compiler vs Interpreter-Compiler design ppt.Md Hossen
 
Compiler Construction introduction
Compiler Construction introductionCompiler Construction introduction
Compiler Construction introductionRana Ehtisham Ul Haq
 
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 course
Introduction to courseIntroduction to course
Introduction to coursenikit meshram
 
Introduction to Functional Languages
Introduction to Functional LanguagesIntroduction to Functional Languages
Introduction to Functional Languagessuthi
 
4 lexical and syntax
4 lexical and syntax4 lexical and syntax
4 lexical and syntaxMunawar Ahmed
 
4 lexical and syntax analysis
4 lexical and syntax analysis4 lexical and syntax analysis
4 lexical and syntax analysisjigeno
 
Modern Compiler Design
Modern Compiler DesignModern Compiler Design
Modern Compiler Designnextlib
 
Classification of Compilers
Classification of CompilersClassification of Compilers
Classification of CompilersSarmad Ali
 

Viewers also liked (19)

Compiler Design - Introduction to Compiler
Compiler Design - Introduction to CompilerCompiler Design - Introduction to Compiler
Compiler Design - Introduction to Compiler
 
Compiler vs Interpreter-Compiler design ppt.
Compiler vs Interpreter-Compiler design ppt.Compiler vs Interpreter-Compiler design ppt.
Compiler vs Interpreter-Compiler design ppt.
 
Lexical analyzer
Lexical analyzerLexical analyzer
Lexical analyzer
 
Compiler Design Tutorial
Compiler Design Tutorial Compiler Design Tutorial
Compiler Design Tutorial
 
Translators(Compiler, Assembler) and interpreter
Translators(Compiler, Assembler) and interpreterTranslators(Compiler, Assembler) and interpreter
Translators(Compiler, Assembler) and interpreter
 
What is Compiler?
What is Compiler?What is Compiler?
What is Compiler?
 
Compiler Construction introduction
Compiler Construction introductionCompiler Construction introduction
Compiler Construction introduction
 
Phases of the Compiler - Systems Programming
Phases of the Compiler - Systems ProgrammingPhases of the Compiler - Systems Programming
Phases of the Compiler - Systems Programming
 
Introduction
IntroductionIntroduction
Introduction
 
Complier designer
Complier designerComplier designer
Complier designer
 
Introduction to course
Introduction to courseIntroduction to course
Introduction to course
 
Introduction to Functional Languages
Introduction to Functional LanguagesIntroduction to Functional Languages
Introduction to Functional Languages
 
Current Trends in HPC
Current Trends in HPCCurrent Trends in HPC
Current Trends in HPC
 
4 lexical and syntax
4 lexical and syntax4 lexical and syntax
4 lexical and syntax
 
4 lexical and syntax analysis
4 lexical and syntax analysis4 lexical and syntax analysis
4 lexical and syntax analysis
 
Passescd
PassescdPassescd
Passescd
 
Modern Compiler Design
Modern Compiler DesignModern Compiler Design
Modern Compiler Design
 
Classification of Compilers
Classification of CompilersClassification of Compilers
Classification of Compilers
 
LR Parsing
LR ParsingLR Parsing
LR Parsing
 

Similar to Compiler Design Basics

Compiler Design Basics
Compiler Design BasicsCompiler Design Basics
Compiler Design BasicsAkhil Kaushik
 
Introduction to Compilers
Introduction to CompilersIntroduction to Compilers
Introduction to CompilersAkhil Kaushik
 
Compiler Design Introduction
Compiler Design Introduction Compiler Design Introduction
Compiler Design Introduction Thapar Institute
 
4_5802928814682016556.pptx
4_5802928814682016556.pptx4_5802928814682016556.pptx
4_5802928814682016556.pptxAshenafiGirma5
 
Cd ch1 - introduction
Cd   ch1 - introductionCd   ch1 - introduction
Cd ch1 - introductionmengistu23
 
CD - CH1 - Introduction to compiler design.pptx
CD - CH1 - Introduction to compiler design.pptxCD - CH1 - Introduction to compiler design.pptx
CD - CH1 - Introduction to compiler design.pptxZiyadMohammed17
 
aditya malkani compiler.pptx
aditya malkani compiler.pptxaditya malkani compiler.pptx
aditya malkani compiler.pptxWildVenomOP
 
Week 08_Basics of Compiler Construction.pdf
Week 08_Basics of Compiler Construction.pdfWeek 08_Basics of Compiler Construction.pdf
Week 08_Basics of Compiler Construction.pdfAnonymousQ3EMYoWNS
 
Compiler Design Introduction
Compiler Design IntroductionCompiler Design Introduction
Compiler Design IntroductionKuppusamy P
 
Compiler an overview
Compiler  an overviewCompiler  an overview
Compiler an overviewamudha arul
 
X-CS-8.0 Programming in C Language 2022-2023.pdf
X-CS-8.0 Programming in C Language 2022-2023.pdfX-CS-8.0 Programming in C Language 2022-2023.pdf
X-CS-8.0 Programming in C Language 2022-2023.pdfAlefya1
 
PCSG_Computer_Science_Unit_1_Lecture_2.pptx
PCSG_Computer_Science_Unit_1_Lecture_2.pptxPCSG_Computer_Science_Unit_1_Lecture_2.pptx
PCSG_Computer_Science_Unit_1_Lecture_2.pptxAliyahAli19
 
compiler construction tool in computer science .
compiler construction tool in computer science .compiler construction tool in computer science .
compiler construction tool in computer science .RanitHalder
 
Session01 basics programming
Session01 basics programmingSession01 basics programming
Session01 basics programmingHarithaRanasinghe
 
Phases of Compiler.pptx
Phases of Compiler.pptxPhases of Compiler.pptx
Phases of Compiler.pptxssuser3b4934
 
Lecture 1 introduction to language processors
Lecture 1  introduction to language processorsLecture 1  introduction to language processors
Lecture 1 introduction to language processorsRebaz Najeeb
 

Similar to Compiler Design Basics (20)

Compiler Design Basics
Compiler Design BasicsCompiler Design Basics
Compiler Design Basics
 
Introduction to Compilers
Introduction to CompilersIntroduction to Compilers
Introduction to Compilers
 
Compiler Design Introduction
Compiler Design Introduction Compiler Design Introduction
Compiler Design Introduction
 
4_5802928814682016556.pptx
4_5802928814682016556.pptx4_5802928814682016556.pptx
4_5802928814682016556.pptx
 
Cd ch1 - introduction
Cd   ch1 - introductionCd   ch1 - introduction
Cd ch1 - introduction
 
CD - CH1 - Introduction to compiler design.pptx
CD - CH1 - Introduction to compiler design.pptxCD - CH1 - Introduction to compiler design.pptx
CD - CH1 - Introduction to compiler design.pptx
 
COMPILER DESIGN PPTS.pptx
COMPILER DESIGN PPTS.pptxCOMPILER DESIGN PPTS.pptx
COMPILER DESIGN PPTS.pptx
 
Compilers.pptx
Compilers.pptxCompilers.pptx
Compilers.pptx
 
aditya malkani compiler.pptx
aditya malkani compiler.pptxaditya malkani compiler.pptx
aditya malkani compiler.pptx
 
Week 08_Basics of Compiler Construction.pdf
Week 08_Basics of Compiler Construction.pdfWeek 08_Basics of Compiler Construction.pdf
Week 08_Basics of Compiler Construction.pdf
 
Chapter 1.pptx
Chapter 1.pptxChapter 1.pptx
Chapter 1.pptx
 
Compiler Design Introduction
Compiler Design IntroductionCompiler Design Introduction
Compiler Design Introduction
 
Compiler an overview
Compiler  an overviewCompiler  an overview
Compiler an overview
 
X-CS-8.0 Programming in C Language 2022-2023.pdf
X-CS-8.0 Programming in C Language 2022-2023.pdfX-CS-8.0 Programming in C Language 2022-2023.pdf
X-CS-8.0 Programming in C Language 2022-2023.pdf
 
PCSG_Computer_Science_Unit_1_Lecture_2.pptx
PCSG_Computer_Science_Unit_1_Lecture_2.pptxPCSG_Computer_Science_Unit_1_Lecture_2.pptx
PCSG_Computer_Science_Unit_1_Lecture_2.pptx
 
compiler construction tool in computer science .
compiler construction tool in computer science .compiler construction tool in computer science .
compiler construction tool in computer science .
 
Chap01-Intro.ppt
Chap01-Intro.pptChap01-Intro.ppt
Chap01-Intro.ppt
 
Session01 basics programming
Session01 basics programmingSession01 basics programming
Session01 basics programming
 
Phases of Compiler.pptx
Phases of Compiler.pptxPhases of Compiler.pptx
Phases of Compiler.pptx
 
Lecture 1 introduction to language processors
Lecture 1  introduction to language processorsLecture 1  introduction to language processors
Lecture 1 introduction to language processors
 

More from Akhil Kaushik

HDLC & basic protocols
HDLC & basic protocolsHDLC & basic protocols
HDLC & basic protocolsAkhil Kaushik
 
Interactive teaching methodologies
Interactive teaching methodologiesInteractive teaching methodologies
Interactive teaching methodologiesAkhil Kaushik
 
Role of media in rural society
Role of media in rural societyRole of media in rural society
Role of media in rural societyAkhil Kaushik
 
Introduction to Genetic algorithms
Introduction to Genetic algorithmsIntroduction to Genetic algorithms
Introduction to Genetic algorithmsAkhil Kaushik
 
E-com, E-payment & EDI
E-com, E-payment & EDIE-com, E-payment & EDI
E-com, E-payment & EDIAkhil Kaushik
 
Computer Networking basics
Computer Networking basicsComputer Networking basics
Computer Networking basicsAkhil Kaushik
 
AI and Expert Systems
AI and Expert SystemsAI and Expert Systems
AI and Expert SystemsAkhil Kaushik
 
An eye opener on female foeticide
An eye opener on female foeticideAn eye opener on female foeticide
An eye opener on female foeticideAkhil Kaushik
 

More from Akhil Kaushik (15)

E commerce unit 2
E commerce unit 2E commerce unit 2
E commerce unit 2
 
E commerce unit 3
E commerce unit 3E commerce unit 3
E commerce unit 3
 
Effective googloing
Effective googloingEffective googloing
Effective googloing
 
HDLC & basic protocols
HDLC & basic protocolsHDLC & basic protocols
HDLC & basic protocols
 
HTML basics
HTML basicsHTML basics
HTML basics
 
Interactive teaching methodologies
Interactive teaching methodologiesInteractive teaching methodologies
Interactive teaching methodologies
 
Role of media in rural society
Role of media in rural societyRole of media in rural society
Role of media in rural society
 
Multimedia Basics
Multimedia BasicsMultimedia Basics
Multimedia Basics
 
Introduction to Genetic algorithms
Introduction to Genetic algorithmsIntroduction to Genetic algorithms
Introduction to Genetic algorithms
 
E-com, E-payment & EDI
E-com, E-payment & EDIE-com, E-payment & EDI
E-com, E-payment & EDI
 
E commerce unit 1
E  commerce unit 1E  commerce unit 1
E commerce unit 1
 
Computer Networking basics
Computer Networking basicsComputer Networking basics
Computer Networking basics
 
ARPANET
ARPANETARPANET
ARPANET
 
AI and Expert Systems
AI and Expert SystemsAI and Expert Systems
AI and Expert Systems
 
An eye opener on female foeticide
An eye opener on female foeticideAn eye opener on female foeticide
An eye opener on female foeticide
 

Recently uploaded

Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesFatimaKhan178732
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application ) Sakshi Ghasle
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppCeline George
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting DataJhengPantaleon
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
Class 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdfClass 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdfakmcokerachita
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsKarinaGenton
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
Concept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfConcept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfUmakantAnnand
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfSumit Tiwari
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 

Recently uploaded (20)

Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and Actinides
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application )
 
Staff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSDStaff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSD
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website App
 
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
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Class 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdfClass 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdf
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its Characteristics
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
Concept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfConcept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.Compdf
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 

Compiler Design Basics

  • 2. Table of Contents • Introduction. • History. • Why study Compiler? • Translators. • Structure of Compiler. • Compiler Construction Tools.
  • 3. Introduction • A compiler is a computer program (or set of programs) that transforms source code written in a high level language (the source language) into low level language (the target language may be assembly language or machine language (0.1)).
  • 5. Introduction Compiler basically does two things: • Analysis: Compiling source code & detecting errors in it. • Synthesis: Translating the source code into object code depending upon the type of machine.
  • 6. Introduction • Program errors are difficult to track if the compiler is wrongly designed. • Hence compiler construction is a very tedious and long process.
  • 7. Introduction • One-pass compiler: It compiles the that passes through the source code of each compilation unit only once. • They are faster than multi-pass compiler. • Their efficiency is limited because they don’t produce intermediate codes which can be refined easily. • Also known as ‘Narrow Compiler’.
  • 8. Introduction • Multi-pass compiler: It processes the source code or abstract syntax tree of a program several times. • It may create one or more intermediate codes (easy to refine). • Each pass takes output of previous phase as input; hence requires less memory. • Also known as ‘Wide Compiler’.
  • 9. History • Software for early computers were written in assembly language. • The need of reusability of code gave birth to programming languages. • This need grow huge to overcome the cost restriction of compiler.
  • 10. History • The concept of machine independent programming gave birth to the need of compilers in 1950s. • The 1st compiler was written by Grace Hopper in 1952 for A-0 programming language.
  • 11. History • The 1st complete compiler was developed by FORTRAN team lead by John Backus @ IBM in 1957. • COBOL was the 1st language to be compiled on multiple platforms in 1960.
  • 12. History • Earlier compilers were written in assembly languages. • The 1st compiler in HLL was created for LISP by Tim Hart & Mike Levin @ MIT, USA in 1962, which was a self- hosting Compiler.
  • 13. History • Most compilers are made in C or Pascal languages. • However the trend is changing to self-hosting compilers, which can compile the source code of the same language in which they are created.
  • 14. Why Study Compiler? • Its essential to understand the heart of programming by computer engineering students. • There may be need of designing a compiler for any software language in the profession.
  • 15. Why Study Compiler? • Increases understanding of language semantics. • Helps to handle language performance issues. • Opportunity for non-trivial programming project
  • 16. Translators • It is important to understand that compiler is a kind of translator, which translates high level language (human understandable) to low-level language(machine understandable).
  • 17. Translators • Interpreter: This software converts the high-level language into low-level language line by line. • It takes less memory than compiler. • It takes more time than compiler. • It is more efficient in error detection than compiler. • It takes more time to build.
  • 18. Translators • Assembler: This software converts the assembly language (assembly instruction mnemonics) into machine level language (opcodes i.e.0,1). • It offers reusability of assembly codes on different machine platforms.
  • 19. Translators • Cross-Compiler: If the compiled program can run on a computer whose C.P.U or O.S is different from the one on which the compiler runs, the compiler is known as a cross- complier.
  • 20. Translators • Language Translator / Source to source translator / Language Converter: It converts programs in one high-level language to another high-level language. • Ex: From Java code to ASP.Net code
  • 21. Translators • Language Rewriter: It is a program that changes form of expression of the same language. • It does not changes the language of source code.
  • 22. Translators • Decompiler: It is a piece of software that converts the low-level language to high-level language . • It is not as famous, but may prove a useful tool sometimes.
  • 23. Translators • Compiler-Compiler: It is a tool that creates a compiler, interpreter or parser from the information provided on formal description of any language. • The earliest & most common type is parser-generator.
  • 24. Translators • Linker: It is a program that combines object modules(object programs) to form executable program. • Each module of software is compiled separately to produce object programs. • Linker will combine all object modules & give it to loader for loading it in memory.
  • 25. Translators • Loader: It is a program which accepts input as linked modules & loads them into main memory for execution. • It copies modules from secondary memory to main memory. • It may also replace virtual addresses with physical addresses. • Linker & Loader may overlap.
  • 26. Structure of Compiler • Compilers bridge the gap b/w high level language & machine hardware. • Compiler requires: 1. Finding errors in syntax of program. 2. Generating correct & efficient object code. 3. Run-time organization. 4. Formatting o/p acc. to linker/ assembler.
  • 28. Structure of Compiler Compilation- Front End (also known as Analysis Part) • Lexical Analysis • Syntax Analysis • Semantic Analysis • Intermediate Code Generation * => Front end is machine independent.
  • 29. Structure of Compiler Compilation- Front End • Determines operations implied by the source program which are recorded in a tree structure called the Syntax Tree. • Breaks up the source code into basic pieces, while storing info. in the symbol table
  • 30. Structure of Compiler Compilation- Back End (also known as Synthesis Part ) • Code Optimization • Code Generation * => Back end is machine dependent.
  • 31. Structure of Compiler Compilation- Back End • Constructs the target code from the syntax tree, and from the information in the symbol table. • Here, code optimization offers efficiency of code generation with least use of resources.
  • 32. Structure of Compiler Lexical Analysis • Initial part of reading and analyzing the program text. • Text is read and divided into tokens, each of which corresponds to a symbol in the programming language. • Ex: Variable, keyword, delimiters or digits.
  • 33. Structure of Compiler Lexical Analysis Ex: a = b + 5 – (c * d) Token Type Value Identifier a, b, c, d Operator +, -, * Constant 5 Delimiter (, )
  • 34. Structure of Compiler Syntax Analysis • It takes list of tokens produced by lexical analysis. • Then, these tokens are arranged in a tree like structure (Syntax tree), which reflects program structure. • Also known as Parsing.
  • 35. Structure of Compiler Semantic Analysis • It validates the syntax tree by applying rules & regulations of the target language. • It does type checking, scope resolution, variable declaration, etc. • It decorates the syntax tree by putting data types, values, etc.
  • 36. Structure of Compiler Intermediate Code Generation • The program is translated to a simple machine independent intermediate language. • Register allocation of variables is done in this phase.
  • 37. Structure of Compiler Code Optimization • It aims to reduce process timings of any program. • It produces efficient programming code. • It is an optional phase.
  • 38. Structure of Compiler Code Optimization • Removing unreachable code. • Getting rid of unused variables • Eliminating multiplication by 1 and addition by 0 • Removing statements that are not modified from the loop • Common sub-expression elimination.
  • 39. Structure of Compiler Code Generation • Target program is generated in the machine language of the target architecture. • Memory locations are selected for each variable. • Instructions are chosen for each operation • Individual tree nodes are translated into sequence of m/c language instructions.
  • 40. Structure of Compiler Symbol Table • It stores identifiers identified in lexical analysis. • It adds type and scope information during syntactical and semantical analysis. • Also used for ‘Live analysis’ in optimization. • This info is used in code generation to find which instructions to use.
  • 41. Structure of Compiler Error Handler • It handles error handling & reporting during many phases. • Ex: Invalid character sequence in scanning, invalid token sequences in parsing, type & scope errors in semantic analysis.
  • 42. Compiler Construction Tools • Compiler construction tools were introduced after widespread of computers. • Also known as compiler- compilers, compiler- generators or translator writing systems. • These tools may use sophisticated algo. or specified languages for specifying & implementing the component.
  • 43. Compiler Construction Tools • Scanner Generators: These generate lexical analyzers. • The basic lexical analyzer is produced by Finite Automata, which takes input in form of regular expressions. • Ex: LEX for Unix O.S.
  • 44. Compiler Construction Tools • Parser Generators: These software produce syntax analyzers which takes input based on context-free grammar. • Earlier, used to be most difficult to develop but now, easier to develop & implement.
  • 45. Compiler Construction Tools • Syntax-directed Translation Engines: These s/w products produce intermediate code with the help of parse tree. • Main idea is associating 1 or more translations with each node of parse tree. • Each node is defined in terms of translations at its neighboring nodes in the tree.
  • 46. Compiler Construction Tools • Automatic Code Generator: This software basically take intermediate code as input & produce machine language as output. • It is capable of fetching data from various storage locations like registers, static memory, stack, etc. • Basic technique here is ‘template matching’.
  • 47. Compiler Construction Tools • Data Flow Engines: It is a tool used for code optimization. • Info is supplied by user & intermediate code is compared to analyze the relation. • It also does data-flow analysis i.e. finding out how values are transmitted from one part to another part of the program.
  • 48. Further Contact Details For any queries, please contact me at: akhil1681@gmail.com Or http://akhil1681.blogspot.com