SlideShare una empresa de Scribd logo
1 de 49
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
Need for programming languages?
• Closer to human thinking behavior.
• Program’s size is shorter.
• Error detection is easy.
• Same program can be compiled in
accordance to different machine
architectures.
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

Más contenido relacionado

La actualidad más candente

La actualidad más candente (20)

Techniques & applications of Compiler
Techniques & applications of CompilerTechniques & applications of Compiler
Techniques & applications of Compiler
 
basics of compiler design
basics of compiler designbasics of compiler design
basics of compiler design
 
Chapter 1 1
Chapter 1 1Chapter 1 1
Chapter 1 1
 
Compiler Design
Compiler DesignCompiler Design
Compiler Design
 
Introduction to compiler
Introduction to compilerIntroduction to compiler
Introduction to compiler
 
Lecture 1 introduction to language processors
Lecture 1  introduction to language processorsLecture 1  introduction to language processors
Lecture 1 introduction to language processors
 
Lecture 01 introduction to compiler
Lecture 01 introduction to compilerLecture 01 introduction to compiler
Lecture 01 introduction to compiler
 
Compiler1
Compiler1Compiler1
Compiler1
 
Introduction to Compiler Construction
Introduction to Compiler Construction Introduction to Compiler Construction
Introduction to Compiler Construction
 
Compiler Construction
Compiler ConstructionCompiler Construction
Compiler Construction
 
Principles of compiler design
Principles of compiler designPrinciples of compiler design
Principles of compiler design
 
Compiler design Introduction
Compiler design IntroductionCompiler design Introduction
Compiler design Introduction
 
Compiler
CompilerCompiler
Compiler
 
Phases of compiler
Phases of compilerPhases of compiler
Phases of compiler
 
Compiler Design Material
Compiler Design MaterialCompiler Design Material
Compiler Design Material
 
Compiler Construction
Compiler ConstructionCompiler Construction
Compiler Construction
 
Compilers
CompilersCompilers
Compilers
 
Compiler Design Lecture Notes
Compiler Design Lecture NotesCompiler Design Lecture Notes
Compiler Design Lecture Notes
 
Lecture2 general structure of a compiler
Lecture2 general structure of a compilerLecture2 general structure of a compiler
Lecture2 general structure of a compiler
 
Ch1
Ch1Ch1
Ch1
 

Similar a Compiler Design Basics

Compiler Design Basics
Compiler Design BasicsCompiler Design Basics
Compiler Design BasicsAkhil 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
 
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
 
aditya malkani compiler.pptx
aditya malkani compiler.pptxaditya malkani compiler.pptx
aditya malkani compiler.pptxWildVenomOP
 
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
 
Compiler an overview
Compiler  an overviewCompiler  an overview
Compiler an overviewamudha arul
 
Compiler Construction Lecture One .pptx
Compiler Construction Lecture One  .pptxCompiler Construction Lecture One  .pptx
Compiler Construction Lecture One .pptxانشال عارف
 
Phases of Compiler.pptx
Phases of Compiler.pptxPhases of Compiler.pptx
Phases of Compiler.pptxssuser3b4934
 
Life cycle of a computer program
Life cycle of a computer programLife cycle of a computer program
Life cycle of a computer programAbhay Kumar
 
Compiler Design Introduction
Compiler Design IntroductionCompiler Design Introduction
Compiler Design IntroductionKuppusamy P
 
Language translator
Language translatorLanguage translator
Language translatorasmakh89
 
COMPILER DESIGN.pdf
COMPILER DESIGN.pdfCOMPILER DESIGN.pdf
COMPILER DESIGN.pdfAdiseshaK
 

Similar a Compiler Design Basics (20)

Compiler Design Basics
Compiler Design BasicsCompiler Design Basics
Compiler Design Basics
 
Compiler Design Introduction
Compiler Design Introduction Compiler Design Introduction
Compiler Design Introduction
 
COMPILER DESIGN PPTS.pptx
COMPILER DESIGN PPTS.pptxCOMPILER DESIGN PPTS.pptx
COMPILER DESIGN PPTS.pptx
 
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
 
Compilers.pptx
Compilers.pptxCompilers.pptx
Compilers.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
 
aditya malkani compiler.pptx
aditya malkani compiler.pptxaditya malkani compiler.pptx
aditya malkani compiler.pptx
 
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
 
Compiler an overview
Compiler  an overviewCompiler  an overview
Compiler an overview
 
Compiler Construction Lecture One .pptx
Compiler Construction Lecture One  .pptxCompiler Construction Lecture One  .pptx
Compiler Construction Lecture One .pptx
 
Phases of Compiler.pptx
Phases of Compiler.pptxPhases of Compiler.pptx
Phases of Compiler.pptx
 
Chap01-Intro.ppt
Chap01-Intro.pptChap01-Intro.ppt
Chap01-Intro.ppt
 
Life cycle of a computer program
Life cycle of a computer programLife cycle of a computer program
Life cycle of a computer program
 
Compiler Design Introduction
Compiler Design IntroductionCompiler Design Introduction
Compiler Design Introduction
 
Language translator
Language translatorLanguage translator
Language translator
 
COMPILER DESIGN.pdf
COMPILER DESIGN.pdfCOMPILER DESIGN.pdf
COMPILER DESIGN.pdf
 
Introduction to Compiler design
Introduction to Compiler design Introduction to Compiler design
Introduction to Compiler design
 

Más de Akhil Kaushik

Symbol Table, Error Handler & Code Generation
Symbol Table, Error Handler & Code GenerationSymbol Table, Error Handler & Code Generation
Symbol Table, Error Handler & Code GenerationAkhil Kaushik
 
Parsing in Compiler Design
Parsing in Compiler DesignParsing in Compiler Design
Parsing in Compiler DesignAkhil Kaushik
 
Context Free Grammar
Context Free GrammarContext Free Grammar
Context Free GrammarAkhil Kaushik
 
Error Detection & Recovery
Error Detection & RecoveryError Detection & Recovery
Error Detection & RecoveryAkhil Kaushik
 
Lexical Analyzer Implementation
Lexical Analyzer ImplementationLexical Analyzer Implementation
Lexical Analyzer ImplementationAkhil Kaushik
 
Lexical Analysis - Compiler Design
Lexical Analysis - Compiler DesignLexical Analysis - Compiler Design
Lexical Analysis - Compiler DesignAkhil Kaushik
 
File Handling Python
File Handling PythonFile Handling Python
File Handling PythonAkhil Kaushik
 
Algorithms & Complexity Calculation
Algorithms & Complexity CalculationAlgorithms & Complexity Calculation
Algorithms & Complexity CalculationAkhil Kaushik
 
Intro to Data Structure & Algorithms
Intro to Data Structure & AlgorithmsIntro to Data Structure & Algorithms
Intro to Data Structure & AlgorithmsAkhil Kaushik
 
Decision Making & Loops
Decision Making & LoopsDecision Making & Loops
Decision Making & LoopsAkhil Kaushik
 
Basic programs in Python
Basic programs in PythonBasic programs in Python
Basic programs in PythonAkhil Kaushik
 
Introduction to Python Programming
Introduction to Python ProgrammingIntroduction to Python Programming
Introduction to Python ProgrammingAkhil Kaushik
 
Bootstrapping in Compiler
Bootstrapping in CompilerBootstrapping in Compiler
Bootstrapping in CompilerAkhil Kaushik
 

Más de Akhil Kaushik (19)

Symbol Table, Error Handler & Code Generation
Symbol Table, Error Handler & Code GenerationSymbol Table, Error Handler & Code Generation
Symbol Table, Error Handler & Code Generation
 
Code Optimization
Code OptimizationCode Optimization
Code Optimization
 
Parsing in Compiler Design
Parsing in Compiler DesignParsing in Compiler Design
Parsing in Compiler Design
 
Context Free Grammar
Context Free GrammarContext Free Grammar
Context Free Grammar
 
Error Detection & Recovery
Error Detection & RecoveryError Detection & Recovery
Error Detection & Recovery
 
Symbol Table
Symbol TableSymbol Table
Symbol Table
 
Lexical Analyzer Implementation
Lexical Analyzer ImplementationLexical Analyzer Implementation
Lexical Analyzer Implementation
 
NFA & DFA
NFA & DFANFA & DFA
NFA & DFA
 
Lexical Analysis - Compiler Design
Lexical Analysis - Compiler DesignLexical Analysis - Compiler Design
Lexical Analysis - Compiler Design
 
File Handling Python
File Handling PythonFile Handling Python
File Handling Python
 
Regular Expressions
Regular ExpressionsRegular Expressions
Regular Expressions
 
Algorithms & Complexity Calculation
Algorithms & Complexity CalculationAlgorithms & Complexity Calculation
Algorithms & Complexity Calculation
 
Intro to Data Structure & Algorithms
Intro to Data Structure & AlgorithmsIntro to Data Structure & Algorithms
Intro to Data Structure & Algorithms
 
Decision Making & Loops
Decision Making & LoopsDecision Making & Loops
Decision Making & Loops
 
Basic programs in Python
Basic programs in PythonBasic programs in Python
Basic programs in Python
 
Python Data-Types
Python Data-TypesPython Data-Types
Python Data-Types
 
Introduction to Python Programming
Introduction to Python ProgrammingIntroduction to Python Programming
Introduction to Python Programming
 
Bootstrapping in Compiler
Bootstrapping in CompilerBootstrapping in Compiler
Bootstrapping in Compiler
 
Phases of compiler
Phases of compilerPhases of compiler
Phases of compiler
 

Último

Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfSherif Taha
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxVishalSingh1417
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhikauryashika82
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17Celine George
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Jisc
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfagholdier
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxnegromaestrong
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentationcamerronhm
 
Dyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptxDyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptxcallscotland1987
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17Celine George
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...pradhanghanshyam7136
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxSKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxAmanpreet Kaur
 
Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Association for Project Management
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...Nguyen Thanh Tu Collection
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxVishalSingh1417
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfPoh-Sun Goh
 

Último (20)

Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
Spatium Project Simulation student brief
Spatium Project Simulation student briefSpatium Project Simulation student brief
Spatium Project Simulation student brief
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 
Dyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptxDyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptx
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxSKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
 
Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptx
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 

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 Need for programming languages? • Closer to human thinking behavior. • Program’s size is shorter. • Error detection is easy. • Same program can be compiled in accordance to different machine architectures.
  • 8. 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’.
  • 9. 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’.
  • 10. 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.
  • 11. 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.
  • 12. 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.
  • 13. 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.
  • 14. 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.
  • 15. 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.
  • 16. Why Study Compiler? • Increases understanding of language semantics. • Helps to handle language performance issues. • Opportunity for non-trivial programming project
  • 17. 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).
  • 18. 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.
  • 19. 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.
  • 20. 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.
  • 21. 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
  • 22. 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.
  • 23. 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.
  • 24. 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.
  • 25. 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.
  • 26. 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.
  • 27. 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.
  • 29. 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.
  • 30. 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
  • 31. Structure of Compiler Compilation- Back End (also known as Synthesis Part ) • Code Optimization • Code Generation * => Back end is machine dependent.
  • 32. 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.
  • 33. 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.
  • 34. Structure of Compiler Lexical Analysis Ex: a = b + 5 – (c * d) Token Type Value Identifier a, b, c, d Operator +, -, * Constant 5 Delimiter (, )
  • 35. 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.
  • 36. 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.
  • 37. 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.
  • 38. Structure of Compiler Code Optimization • It aims to reduce process timings of any program. • It produces efficient programming code. • It is an optional phase.
  • 39. 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.
  • 40. 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.
  • 41. 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.
  • 42. 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.
  • 43. 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.
  • 44. 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.
  • 45. 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.
  • 46. 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.
  • 47. 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’.
  • 48. 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.
  • 49. Further Contact Details For any queries, please contact me at: akhil1681@gmail.com Or http://akhil1681.blogspot.com