SlideShare ist ein Scribd-Unternehmen logo
1 von 42
Compiler Design
(CSE-405-F)
Akhil Kaushik
Asstt. Prof., CE Deptt.,
TIT Bhiwani
Programming….Why?
What is a Compiler?
• 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)).
What is a Compiler?
What is a Compiler?
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.
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’.
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’.
Type of Languages
1. Binary Level
Language
2. Assembly Level
Language
3. High Level
Language
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.
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 science 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
Translators - Preprocessor
• It is a program that processes its input data to
produce output that is used as input to another
program.
• The output is said to be a preprocessed form of the
input data, which is often used by some subsequent
programs like compilers.
Translators - Preprocessor
• The amount and kind of processing done depends on
the nature of the preprocessor.
• some preprocessors are only capable of performing
simple textual substitutions and macro expansions,
while others have the power of full-
fledged programming languages.
• It can also include macro processing, file inclusion and
language extensions.
Translators - Interpreter
• It is another common kind of language processor.
• Instead of producing a target program as a
translation, it directly execute the operations
specified in the source program on inputs supplied
by the user.
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 - Interpreter
• Java language processors combine compilation
and interpretation.
• A Java source program may first be compiled into
an intermediate form called bytecodes.
• The bytecodes are then interpreted by a virtual
machine.
• A benefit of this arrangement is that bytecodes
compiled on one machine can be interpreted on
another machine, perhaps across a network.
Translators - Interpreter
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 - Assembler
• It generates instructions by evaluating the
mnemonics (symbols) in operation field and find
the value of symbol and literals to produce
machine code.
• Now, if assembler do all this work in one scan then
it is called single pass assembler, otherwise if it
does in multiple scans then called multiple pass
assembler.
Translators - Assembler
• Pass-1:
– Define symbols and literals and remember them in
symbol table and literal table respectively.
– Keep track of location counter
– Process pseudo-operations
• Pass-2:
– Generate object code by converting symbolic op-code
into respective numeric op-code
– Generate data for literals and look for values of
symbols
Translators - Assembler
Translators - Linker
• A linker is a program that allows a user
to link library programs or separate
modules of code into their own
programs.
• It is used to combine different modules
of object code into one single
executable code program.
Translators - Linker
• This may involve combining a program with library
programs, or involve recombining blocks of object
code from the same program, or a mixture of both.
• The linker program is used to recombine the
blocks of object code in RAM to get a working full
program.
• Linker is helpful if there is a shortage of RAM.
Translators - Loader
• A loader is a piece of software that chooses
exactly where to put object code in RAM, ready for
it to be run.
• It also adjusts the memory references in programs.
Translators - Loader
• Programs can be written by programmers using
either ‘absolute addressing’ or ‘relative addressing’.
• Relative addressing is more common because then
the loader can put the program anywhere in RAM -
absolute addressing isn't flexible.
• Linker & Loader may overlap.
Translators - Loader
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 - Cross-Compiler
Translator – Language Converter
• Also called Language Translator / Source to
source translator.
• It converts programs in one high-level language to
another high-level language.
• Ex: Cfront converts C++ into C language.
Translator – Language Rewriter
• It is a program that changes
form of expression of the same
language.
• It does not changes the
language of source code.
Translator - 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.
• Ex: JD Compiler, .JAD decompiler, NET Reflector
Translator – 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.
• It is also called compiler-generator.
• Ex: Yacc, JavaCC, etc.
CONTACT ME AT:
Akhil Kaushik
akhilkaushik05@gmail.com
9416910303
CONTACT ME AT:
Akhil Kaushik
akhilkaushik05@gmail.com
9416910303
Thank You !!!

Weitere ähnliche Inhalte

Was ist angesagt? (20)

C programming
C programmingC programming
C programming
 
Lecture 01 introduction to compiler
Lecture 01 introduction to compilerLecture 01 introduction to compiler
Lecture 01 introduction to compiler
 
compiler and their types
compiler and their typescompiler and their types
compiler and their types
 
Core java complete ppt(note)
Core java  complete  ppt(note)Core java  complete  ppt(note)
Core java complete ppt(note)
 
loaders and linkers
 loaders and linkers loaders and linkers
loaders and linkers
 
Types of Compilers
Types of CompilersTypes of Compilers
Types of Compilers
 
Compiler1
Compiler1Compiler1
Compiler1
 
Language Translator ( Compiler)
Language Translator ( Compiler)Language Translator ( Compiler)
Language Translator ( Compiler)
 
Introduction Of C++
Introduction Of C++Introduction Of C++
Introduction Of C++
 
Compiler design
Compiler designCompiler design
Compiler design
 
Compiler Construction
Compiler ConstructionCompiler Construction
Compiler Construction
 
Language translator
Language translatorLanguage translator
Language translator
 
Functional Programming Fundamentals
Functional Programming FundamentalsFunctional Programming Fundamentals
Functional Programming Fundamentals
 
Compilers
CompilersCompilers
Compilers
 
Compiler vs interpreter
Compiler vs interpreterCompiler vs interpreter
Compiler vs interpreter
 
COMPUTER PROGRAMMING
COMPUTER PROGRAMMINGCOMPUTER PROGRAMMING
COMPUTER PROGRAMMING
 
Machine Translation
Machine TranslationMachine Translation
Machine Translation
 
Program & language generation
Program & language generationProgram & language generation
Program & language generation
 
Basics of c++
Basics of c++Basics of c++
Basics of c++
 
System Programming Overview
System Programming OverviewSystem Programming Overview
System Programming Overview
 

Ähnlich wie Introduction to Compilers

Compiler Design Basics
Compiler Design BasicsCompiler Design Basics
Compiler Design BasicsAkhil Kaushik
 
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
 
4_5802928814682016556.pptx
4_5802928814682016556.pptx4_5802928814682016556.pptx
4_5802928814682016556.pptxAshenafiGirma5
 
Compiler Design Introduction
Compiler Design Introduction Compiler Design Introduction
Compiler Design Introduction Thapar Institute
 
Life cycle of a computer program
Life cycle of a computer programLife cycle of a computer program
Life cycle of a computer programAbhay Kumar
 
Session01 basics programming
Session01 basics programmingSession01 basics programming
Session01 basics programmingHarithaRanasinghe
 
aditya malkani compiler.pptx
aditya malkani compiler.pptxaditya malkani compiler.pptx
aditya malkani compiler.pptxWildVenomOP
 
Transpilers(Source-to-Source Compilers)
Transpilers(Source-to-Source Compilers)Transpilers(Source-to-Source Compilers)
Transpilers(Source-to-Source Compilers)Shivang Bajaniya
 
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
 
Language processing system.pdf
Language processing system.pdfLanguage processing system.pdf
Language processing system.pdfRakibRahman19
 
Compiler - Computer Programming - UOZ
Compiler - Computer Programming - UOZ Compiler - Computer Programming - UOZ
Compiler - Computer Programming - UOZ Safen D Taha
 
Compiler Design Introduction
Compiler Design IntroductionCompiler Design Introduction
Compiler Design IntroductionKuppusamy P
 
computer languages
computer languagescomputer languages
computer languagesRajendran
 
Python-unit -I.pptx
Python-unit -I.pptxPython-unit -I.pptx
Python-unit -I.pptxcrAmth
 

Ähnlich wie Introduction to Compilers (20)

Compiler Design Basics
Compiler Design BasicsCompiler Design Basics
Compiler Design Basics
 
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
 
4_5802928814682016556.pptx
4_5802928814682016556.pptx4_5802928814682016556.pptx
4_5802928814682016556.pptx
 
Compiler Design Introduction
Compiler Design Introduction Compiler Design Introduction
Compiler Design Introduction
 
Life cycle of a computer program
Life cycle of a computer programLife cycle of a computer program
Life cycle of a computer program
 
Session01 basics programming
Session01 basics programmingSession01 basics programming
Session01 basics programming
 
aditya malkani compiler.pptx
aditya malkani compiler.pptxaditya malkani compiler.pptx
aditya malkani compiler.pptx
 
Compilers.pptx
Compilers.pptxCompilers.pptx
Compilers.pptx
 
Transpilers(Source-to-Source Compilers)
Transpilers(Source-to-Source Compilers)Transpilers(Source-to-Source Compilers)
Transpilers(Source-to-Source Compilers)
 
COMPILER DESIGN PPTS.pptx
COMPILER DESIGN PPTS.pptxCOMPILER DESIGN PPTS.pptx
COMPILER DESIGN PPTS.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
 
Introduction to Compiler design
Introduction to Compiler design Introduction to Compiler design
Introduction to Compiler design
 
Language processing system.pdf
Language processing system.pdfLanguage processing system.pdf
Language processing system.pdf
 
Compiler - Computer Programming - UOZ
Compiler - Computer Programming - UOZ Compiler - Computer Programming - UOZ
Compiler - Computer Programming - UOZ
 
Compiler Design Introduction
Compiler Design IntroductionCompiler Design Introduction
Compiler Design Introduction
 
computer languages
computer languagescomputer languages
computer languages
 
Chapter1.pdf
Chapter1.pdfChapter1.pdf
Chapter1.pdf
 
Python-unit -I.pptx
Python-unit -I.pptxPython-unit -I.pptx
Python-unit -I.pptx
 
sege.pdf
sege.pdfsege.pdf
sege.pdf
 

Mehr von 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
 
Compiler construction tools
Compiler construction toolsCompiler construction tools
Compiler construction toolsAkhil Kaushik
 

Mehr von Akhil Kaushik (20)

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
 
Compiler construction tools
Compiler construction toolsCompiler construction tools
Compiler construction tools
 
Phases of compiler
Phases of compilerPhases of compiler
Phases of compiler
 

Kürzlich hochgeladen

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
 
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
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
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
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAssociation for Project Management
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
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
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpinRaunakKeshri1
 
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
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Celine George
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
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
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphThiyagu K
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfchloefrazer622
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajanpragatimahajan3
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 

Kürzlich hochgeladen (20)

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
 
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
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
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
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
 
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
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpin
 
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...
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
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
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdf
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajan
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 

Introduction to Compilers

  • 1. Compiler Design (CSE-405-F) Akhil Kaushik Asstt. Prof., CE Deptt., TIT Bhiwani
  • 3. What is a Compiler? • 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)).
  • 4. What is a Compiler?
  • 5. What is a Compiler? Source Language Target Language
  • 6. 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.
  • 7. Introduction • Program errors are difficult to track, if the compiler is wrongly designed. • Hence, compiler construction is a very tedious and long process.
  • 8. 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. 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. Type of Languages 1. Binary Level Language 2. Assembly Level Language 3. High Level Language
  • 11. 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.
  • 12. 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.
  • 13. 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.
  • 14. 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.
  • 15. 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.
  • 16. 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.
  • 17. Why Study Compiler? • Its essential to understand the heart of programming by computer science engineering students. • There may be need of designing a compiler for any software language in the profession.
  • 18. Why Study Compiler? • Increases understanding of language semantics. • Helps to handle language performance issues. • Opportunity for non-trivial programming project
  • 19. 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).
  • 21. Translators - Preprocessor • It is a program that processes its input data to produce output that is used as input to another program. • The output is said to be a preprocessed form of the input data, which is often used by some subsequent programs like compilers.
  • 22. Translators - Preprocessor • The amount and kind of processing done depends on the nature of the preprocessor. • some preprocessors are only capable of performing simple textual substitutions and macro expansions, while others have the power of full- fledged programming languages. • It can also include macro processing, file inclusion and language extensions.
  • 23. Translators - Interpreter • It is another common kind of language processor. • Instead of producing a target program as a translation, it directly execute the operations specified in the source program on inputs supplied by the user.
  • 24. 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.
  • 25. Translators - Interpreter • Java language processors combine compilation and interpretation. • A Java source program may first be compiled into an intermediate form called bytecodes. • The bytecodes are then interpreted by a virtual machine. • A benefit of this arrangement is that bytecodes compiled on one machine can be interpreted on another machine, perhaps across a network.
  • 27. 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.
  • 28. Translators - Assembler • It generates instructions by evaluating the mnemonics (symbols) in operation field and find the value of symbol and literals to produce machine code. • Now, if assembler do all this work in one scan then it is called single pass assembler, otherwise if it does in multiple scans then called multiple pass assembler.
  • 29. Translators - Assembler • Pass-1: – Define symbols and literals and remember them in symbol table and literal table respectively. – Keep track of location counter – Process pseudo-operations • Pass-2: – Generate object code by converting symbolic op-code into respective numeric op-code – Generate data for literals and look for values of symbols
  • 31. Translators - Linker • A linker is a program that allows a user to link library programs or separate modules of code into their own programs. • It is used to combine different modules of object code into one single executable code program.
  • 32. Translators - Linker • This may involve combining a program with library programs, or involve recombining blocks of object code from the same program, or a mixture of both. • The linker program is used to recombine the blocks of object code in RAM to get a working full program. • Linker is helpful if there is a shortage of RAM.
  • 33. Translators - Loader • A loader is a piece of software that chooses exactly where to put object code in RAM, ready for it to be run. • It also adjusts the memory references in programs.
  • 34. Translators - Loader • Programs can be written by programmers using either ‘absolute addressing’ or ‘relative addressing’. • Relative addressing is more common because then the loader can put the program anywhere in RAM - absolute addressing isn't flexible. • Linker & Loader may overlap.
  • 36. 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.
  • 38. Translator – Language Converter • Also called Language Translator / Source to source translator. • It converts programs in one high-level language to another high-level language. • Ex: Cfront converts C++ into C language.
  • 39. Translator – Language Rewriter • It is a program that changes form of expression of the same language. • It does not changes the language of source code.
  • 40. Translator - 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. • Ex: JD Compiler, .JAD decompiler, NET Reflector
  • 41. Translator – 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. • It is also called compiler-generator. • Ex: Yacc, JavaCC, etc.
  • 42. CONTACT ME AT: Akhil Kaushik akhilkaushik05@gmail.com 9416910303 CONTACT ME AT: Akhil Kaushik akhilkaushik05@gmail.com 9416910303 Thank You !!!