SlideShare una empresa de Scribd logo
1 de 57
Descargar para leer sin conexión
Department of CE / IT
Prof. Dhara Joshi
Unit no : 1
Introduction to
Compiler
(01CE0601)
Introduction to
Compiler
CD:COMPILER DESIGN
Department of CE / IT
Prof. Dhara Joshi
Unit no : 1
Introduction to
Compiler
(01CE0601)
Outline :
Translator
Compiler, Interpreter, Assembler
Cousins of Compiler
Phases of Compiler
Grouping of Phases
Types of Compiler
Compiler construction tools
Pass and Phase
What is
Compiler?
Basic
Terminology
Why we
need it?
Translator
Translator
Translator :
• A translator is a program which takes one program
(written in one language) as input and converts it
into another language (Target language).
• Input Language is Source Language and Output
Language is Target Language.
• There are Three types of Translator :
1) Compiler
2) Interpreter
3) Assembler
 It also detects and reports error during translation.
Compiler
Compiler :
 Compiler is a program that reads a program written in
one language that means source language and
translates it into equivalent program into another
language that is target language.
 Compiler is a program which translates higher level
language into functionally equivalent lower level
language.
 It also detects and reports error.
Source Target
Program Program
Error
Compiler
Interpreter
Interpreter :
 Interpreter is a translator which is used to convert
programs in high-level language to low-level language.
 Interpreter translates line by line and reports the error
once it encountered during the translation process.
Source Target
Program Program
Error
Interpreter
Assembler
Assembler :
 An assembler is a translator used to translate
assembly language to machine language.
 An assembler translates a low-level language, an
assembly language to an even lower-level language,
which is the machine code. The machine code can be
directly understood by the CPU.
Source Target
Program Program
Error
Assembler
Compiler
Vs
Interpreter
Compiler Interpreter
It takes whole program as input It takes single instruction as input
It generates intermediate object
code
It does not generate any
intermediate object code
Memory requirement is more due
to creation of object code.
Memory requirement is less
(memory efficient) as it does not
create intermediate object code.
It takes large amount of time to
analyze the source code but overall
execution is comparatively faster.
It takes less amount of time to
analyze the source code but overall
execution is slower.
Compilation is done before
execution.
Compilation and execution take
place simultaneously.
Display all errors after entire
program is checked.
Display errors of each line one by
one.
Ex : C , C ++ Ex : BASIC , Python
Compiler
Vs
Assembler
Compiler Assembler
Input for compiler is Pre processed
Source code.
Input for Assembler is Assembly
language code.
It generates assembly language
code or directly the executable
code.
It generates the relocatable
machine code.
There are 6 Phases of compiler It makes Two passes over given
input.
Ex : C , C ++ Ex : 8085 , 8086
Language
Processing
System
/ Translation
Processor
/ Context of
Compiler
/Cousins of
Compiler
Pre Processor
Compiler
Assembler
Linker &
Loader
HLL
Pure HLL
Assembly Language
Relocatable Machine code
Absolute Machine code
Library ,
Relocatable object files
Language
Processing
System
/ Translation
Processor
/ Context of
Compiler
/Cousins of
Compiler
 There are three cousins of Compiler
1) Preprocessor
2) Assembler
3) Linker and Loader
Language
Processing
System
/ Translation
Processor
/ Context of
Compiler
/Cousins of
Compiler
1) Preprocessor
 Preprocessor produces input to compilers.
 They may perform the following functions
 Macro Processing : A preprocessor may allow a user to
define macros that are short hands for longer constructs.
File Inclusion : A preprocessor may include header files
into program text.
“Rational” Preprocessor : These processors augment older
languages with more modern flow of control and data
structuring facilities. (Built in Macro for construct like While
or If Statement)
 Language Extension : These processor attempt to add
capabilities to the language by what amount to built in
macros. the language equal is a database query language
embedded in C. statement beginning with ## are taken by
preprocessor to be database access statement unrelated to C
and translated into procedure call on routines that perform
database access.
Language
Processing
System
/ Translation
Processor
/ Context of
Compiler
/Cousins of
Compiler
1) Preprocessor
 Macro processor deal with two kinds of statement
Macro Definition
Macro Use
 Formal Parameters
 Actual Parameters
Language
Processing
System
/ Translation
Processor
/ Context of
Compiler
/Cousins of
Compiler
2) Assembler
 An assembler is a translator used to translate
assembly language to machine language.
 An assembler translates a low-level language, an
assembly language to an even lower-level language,
which is the machine code. The machine code can be
directly understood by the CPU.
Source Target
Program Program
Error
Assembler
Language
Processing
System
/ Translation
Processor
/ Context of
Compiler
/Cousins of
Compiler
2) Assembler
 Assembly code is mnemonic version of machine code,
in which names are used instead of binary codes for
operation and names are also given to memory address.
Language
Processing
System
/ Translation
Processor
/ Context of
Compiler
/Cousins of
Compiler
3) Linker and Loader
 A program called loader performs the two functions of
loading and link editing
 The process of loading consist of taking relocatable
machine code , altering the relocatable address and
placing the altered instructions and data in memory at
the proper location.
 Linker allows us to make a single program from several
files of relocatable machine code.
 Types of Linking : Static and Dynamic
 Types of Loader : Compile and Go loader, Absolute
Loader, Relocating Loader.
Phases of
Compiler
Lexical Analyzer
Phases of
Compiler
/ Analysis –
Synthesis
Model of
Compilation
1) Lexical Analysis
 It is also called Linear analysis or scanning.
 In this phase, input character from source code is read
from left to right and then break into stream of units.
These units are called tokens.
 Sequence of characters having a collective meaning is
called Token.
 Tokens can be categorized into identifiers, constants,
literals, keywords, operators, delimeters etc.
 So, Token is the smallest meaningful entities of program
are produced as output.
Phases of
Compiler
/ Analysis –
Synthesis
Model of
Compilation
1) Lexical Analysis
Example : position = initial + rate * 60
id1 = id2 + id3 * 60
Position Identifier 1
= Equal to operator
Initial Identifier 2
+ Addition Operator
Rate Identifier 3
* Multiplication Operator
60 Constant
Phases of
Compiler
Lexical Analyzer
Syntax Analyzer
Phases of
Compiler
/ Analysis –
Synthesis
Model of
Compilation
2) Syntax Analysis
 It is also called Hierarchical analysis or Parsing.
 It determines if the sentence formed from the words
are syntactically (grammatically) correct.
 It creates syntax tree from generated tokens if the code
is error free.
 Syntax tree consist operators as internal node and
operands as leaf node.
 This phase check each and every line and try to detect
errors if it is grammatically (syntax wise) not correct.
Phases of
Compiler
/ Analysis –
Synthesis
Model of
Compilation
2) Syntax Analysis
position = initial + rate * 60
Three Operators : = + *
position = initial + rate * 60
position = initial + rate * 60
position = initial + rate * 60
Phases of
Compiler
Lexical Analyzer
Syntax Analyzer
Semantic
Analyzer
Phases of
Compiler
/ Analysis –
Synthesis
Model of
Compilation
3) Semantic Analysis
 It determines meaning of string
 In semantic analysis various operations are performed
like
 Performing check ; whether operator have compatible
arguments or not (type checking) , matching of
parenthesis, scope of operation etc.
 Ensuring that components of a program fits together
meaningfully.
Phases of
Compiler
/ Analysis –
Synthesis
Model of
Compilation
3) Semantic Analysis
position = initial + rate * 60
Phases of
Compiler
Lexical Analyzer
Syntax Analyzer
Semantic
Analyzer
Intermediate
Code Generator
Phases of
Compiler
/ Analysis –
Synthesis
Model of
Compilation
4) Intermediate Code Generator
 Intermediate code generation should have two
properties :
it should be easy to produce,
easy to translate.
 Intermediate code is called “Three Address Code”.
 It is called three address code as it maximum consist
three operands.
Phases of
Compiler
/ Analysis –
Synthesis
Model of
Compilation
4) Intermediate Code Generator
Example : position = initial + rate * 60
t1 = inttoreal(60)
t2 = rate * t1
t3 = initial + t2
position = t3
Phases of
Compiler
Lexical Analyzer
Syntax Analyzer
Semantic
Analyzer
Intermediate
Code Generator
Code Optimizer
Phases of
Compiler
/ Analysis –
Synthesis
Model of
Compilation
5) Code Optimization
 This phase improves the intermediate code, in such a
way that a machine code can be produced, which
occupies less memory space and less execution time
without changing the functionality or correctness of
program.
 Example :
t1 = rate * 60.00
position = initial + t1
Phases of
Compiler
Lexical Analyzer
Syntax Analyzer
Semantic
Analyzer
Intermediate
Code Generator
Code Optimizer
Code Generator
Phases of
Compiler
/ Analysis –
Synthesis
Model of
Compilation
6) Code Generation
 In Code generation phase the target code gets
generated.
 In this phase intermediate (optimized) code is
translated into a sequence of machine instructions that
perform the same operation.
 Example :
MOVF id3,R1
MULF #60.00, R1
MOVF id2, R2
ADDF R2, R1
MOVF R1, id1
position = initial + rate * 60
id 1 id2 id3
R1 = id3 (rate)
R1 = 60.00 * R1
R2 = id2 (initial)
R1 = R2 + R1
id1(position) = R1
Phases of
Compiler
Lexical Analyzer
Syntax Analyzer
Semantic
Analyzer
Intermediate
Code Generator
Code Optimizer
Code Generator
Symbol Table
Manager
Error
handler
Phases of
Compiler
Lexical Analyzer
Syntax Analyzer
Semantic
Analyzer
Intermediate
Code Generator
Code Optimizer
Code Generator
Symbol Table
Manager
Error
handler
Analysis Phase
Synthesis Phase
Phases of
Compiler
/ Analysis –
Synthesis
Model of
Compilation
 There are two parts of Compilation Process :
1) Analysis Phase
It breaks up source program into small pieces and
create an intermediate representation of source
program.
2) Synthesis Phase
It constructs the desired target program from
intermediate representation.
Phases of
Compiler
/ Analysis –
Synthesis
Model of
Compilation
1) Analysis Phase
Consist of Three Sub Phases :
 Lexical analysis
 Syntax analysis
 Semantic analysis
2) Synthesis Phase :
Consist of Three Sub Phases :
 Intermediate Code generation
 Code Optimization
 Code Generation
Phases of
Compiler
/ Analysis –
Synthesis
Model of
Compilation
Symbol Table :
 A symbol table is data structure used by language
translators.
 In order to keep track of identifiers used by program,
compiler maintains the record of the same with their
various attributes.
 Symbol table stores information for different entities :
Identifier, Function, Procedure, Constant , Label Name,
Compiler generated temporaries etc.
Phases of
Compiler
/ Analysis –
Synthesis
Model of
Compilation
Error Detection and Recovery :
 Each phase can encounter errors, However after
detecting an error a phase must some how deal with
that error. So that Compilation can proceed, allowing
further errors in the source program to be detected.
 Lexical Analyzer can detect errors where the character
remaining in the input do not form any token of the
language.
 Errors where the token stream violates the structure
rule (syntax) of the language are determined by syntax
analysis phase.
 During Semantic analysis, the compiler tries to detect
constructs that have the right syntactic structure but no
meaning to the operation involved.
Phases of
Compiler
/ Analysis –
Synthesis
Model of
Compilation
Lexical analyzer
Syntax analyzer
Semantic analyzer
a=b+c*60
Id1=id2+id3*60
=
+
*
60
id1
id2
id3
=
+
*
60
id1
id2
id3 Int to float
Intermediate code generator
t1:= inttofloat (60)
t2:= id3 * t1
t3:= id2 + t2
id1:= t3
Code optimizer
t1:= id3 * 60.0
id1:= id2 + t1
Code generator
MOVEF id3, R2
MULF #60.0,R2
MOVF id2, R1
ADDF R2,R1
MOVF R1,id1
Practice Time
Example :
What will be the output of each phase for the following
statement?
Statement : x = a + b * c
Grouping of
Phases
Front End
• Dependent :
Source Language
• Independent :
Target Machine
Back End
• Dependent : Target
Machine
• Independent :
Source Language
Grouping of
Phases
Front End:
 Front end consist of those phase, that depends
preliminary on the source language & are
independent of the target machine.
 It includes Lexical analysis, Syntax analysis, Semantic
analysis, Intermediate code generation and Creation
of Symbol table.
 A certain amount of code optimization can be done
by the front end as well
 The front end also includes error handling that goes
along with each of these phases.
Grouping of
Phases
Back End:
 Back includes those portion of compiler that depend
on the target machine and do not depend on source
language.
 Back end includes code optimization and code
generation with necessary error handling and
symbol table operation.
It has become fairly routine to take front end of a
compiler & redo its back end to produce a compiler for
the same source language on a different machine.
Pass of
Compiler
 One Complete scan of Source program is called Pass.
 Difficulty in single pass :
 Forward Reference : A forward reference means
variable or label is referenced before its declared.
 It leads to Multi-Pass model.
Pass – 1 : Perform analysis of source program and note
relevant information
Pass – 2 : Generate target code using information
noted in pass-1.
START 100 (AD,01) (C,200)
READ A (IS,09) (S,01)
LOOP MOVER AREG , A ..............
........ ...............
........ ...............
BC GT , LOOP ...............
STOP (IS , 00)
A DS 1 (DL,02) (C,1)
.......
Pass Vs Phase
Pass Phase
Various phases are logically grouped
together to form a pass.
The process of compilation is carried
out in various step is called Phase.
Require Less Memory Require More Memory
Execution is faster Execution is slower
Less memory operation(read/write)
to be performed
More memory operations to be
performed
2 Passes of Compiler 6 Phases of Compiler
Types of
Compiler
Native Compiler Cross Compiler
Source to Source
Compiler
Just inTime Compiler
Incremental Compiler Parallelizing Compiler
Types of
Compiler
Native Compiler :
 The compiler used to Compile a source code for
same type of platform only.
 The output generated by this type of compiler can
only be run on the same type of computer system and
OS that the compiler itself runs on.
Cross Compiler :
 The compiler used to compile a source code for
different kinds platform.
 A Cross compiler is a compiler capable of creating
executable code for a platform other than one on
which compiler is running.
Types of
Compiler
Source to Source Compiler :
 The compiler that takes high-level language code as
input and outputs source code of another high- level
language only.
 Unlike other compilers which convert high level
language into low level machine language, it can take
up a code written in Pascal and can transform it into
C-conversion of one high level language into another
high level language having same type of abstraction .
 Thus, it is also known as transpiler .
Types of
Compiler
Just in Time Compiler :
 The compiler which converts a code into machine
code after the program starts execution.
 Convert .java file into .class file.
Types of
Compiler
Incremental Compiler :
 The compiler which compiles only the changed lines
from the source code and update the object code.
Parallelizing Compiler :
 A Compiler which is specially designed to run in
parallel computer architecture is known as
parallelizing compiler.
int a=0;
int b=1;
printf("Enter Input");
Scanf();
if(a==10)
printf();
Compiler
Construction
Tools
Compiler Construction Tools :
1) Scanner Generators
2) Parser Generators
3) Syntax – directed translation engines
4) Automatic Code Generators
5) Data Flow Engine
Compiler
Construction
Tools
Scanner generators: This tool takes regular expressions as
input. For example LEX for Unix Operating System.
Parser generators: A parser generator takes a grammar as
input and automatically generates source code which can
parse streams of characters with the help of a grammar
Syntax-directed translation engines: These software
tools offer an intermediate code by using the parse tree. It
has a goal of associating one or more translations with each
node of the parse tree.
Automatic code generators: Takes intermediate code and
converts them into Machine Language
Data-flow engines: This tool is helpful for code
optimization. Here, information is supplied by user and
intermediate code is compared to analyze any relation. It is
also known as data-flow analysis. It helps you to find out
how values are transmitted from one part of the program to
another part.
Qualities of
Compiler
 Compiler itself must be bug free.
 It must generate correct machine code.
 Generated machine code must run fast (Execution
speed).
 Compilation time must be less.
 Compilation must be portable.
 It must be print good diagnostics and Error message.
 Generated code must work well with existing debugger.
 It must have consistent and Predictable optimization.
References
1. Aho, Lam, Sethi, and Ullman, Compilers: Principles,
Techniques and Tools,SecondEdition, Pearson,
2014
2. D. M. Dhamdhere: Systerm Programming, Mc Graw
Hill Publication
3. Dick Grune, Henri E. Bal, Jacob, Langendoen:
Modern Compiler Design, Wiley India Publication
MU Questions
1) Develop Analysis – Synthesis model of Compiler for
a = b + c * 20. Write down explanation and output
for each phase of compiler.
2) Difference between Compiler and Interpreter.
3) Explain Cousins of compiler.
4) Give the name of Front End and Back End with
explanation, and take one example to show the
output of the every phase.
Department of CE / IT
Prof. Dhara Joshi
Unit no : 1
Introduction to
Compiler
(01CE0601)
Thanks

Más contenido relacionado

La actualidad más candente

La actualidad más candente (19)

Compiler
Compiler Compiler
Compiler
 
Introduction to compiler
Introduction to compilerIntroduction to compiler
Introduction to compiler
 
Concept of compiler in details
Concept of compiler in detailsConcept of compiler in details
Concept of compiler in details
 
Compiler
Compiler Compiler
Compiler
 
Compiler an overview
Compiler  an overviewCompiler  an overview
Compiler an overview
 
Compiler Design
Compiler DesignCompiler Design
Compiler Design
 
Compiler Construction
Compiler ConstructionCompiler Construction
Compiler Construction
 
compiler and their types
compiler and their typescompiler and their types
compiler and their types
 
Presentation compiler design
Presentation compiler designPresentation compiler design
Presentation compiler design
 
Phases of compiler
Phases of compilerPhases of compiler
Phases of compiler
 
Compiler Design(NANTHU NOTES)
Compiler Design(NANTHU NOTES)Compiler Design(NANTHU NOTES)
Compiler Design(NANTHU NOTES)
 
Classification of Compilers
Classification of CompilersClassification of Compilers
Classification of Compilers
 
COMPILER DESIGN OPTIONS
COMPILER DESIGN OPTIONSCOMPILER DESIGN OPTIONS
COMPILER DESIGN OPTIONS
 
Lecture 1 introduction to language processors
Lecture 1  introduction to language processorsLecture 1  introduction to language processors
Lecture 1 introduction to language processors
 
Introduction to Compiler design
Introduction to Compiler design Introduction to Compiler design
Introduction to Compiler design
 
3.2
3.23.2
3.2
 
Introduction to Compilers
Introduction to CompilersIntroduction to Compilers
Introduction to Compilers
 
Compilers
CompilersCompilers
Compilers
 
Introduction to Compiler
Introduction to CompilerIntroduction to Compiler
Introduction to Compiler
 

Similar a unit1pdf__2021_12_14_12_37_34.pdf

Chapter1pdf__2021_11_23_10_53_20.pdf
Chapter1pdf__2021_11_23_10_53_20.pdfChapter1pdf__2021_11_23_10_53_20.pdf
Chapter1pdf__2021_11_23_10_53_20.pdfDrIsikoIsaac
 
Phases of Compiler.pptx
Phases of Compiler.pptxPhases of Compiler.pptx
Phases of Compiler.pptxssuser3b4934
 
Chapter 2 Program language translation.pptx
Chapter 2 Program language translation.pptxChapter 2 Program language translation.pptx
Chapter 2 Program language translation.pptxdawod yimer
 
what is compiler and five phases of compiler
what is compiler and five phases of compilerwhat is compiler and five phases of compiler
what is compiler and five phases of compileradilmehmood93
 
Chapter-1.pptx compiler Design Course Material
Chapter-1.pptx compiler Design Course MaterialChapter-1.pptx compiler Design Course Material
Chapter-1.pptx compiler Design Course MaterialgadisaAdamu
 
2-Design Issues, Patterns, Lexemes, Tokens-28-04-2023.docx
2-Design Issues, Patterns, Lexemes, Tokens-28-04-2023.docx2-Design Issues, Patterns, Lexemes, Tokens-28-04-2023.docx
2-Design Issues, Patterns, Lexemes, Tokens-28-04-2023.docxvenkatapranaykumarGa
 
Pros and cons of c as a compiler language
  Pros and cons of c as a compiler language  Pros and cons of c as a compiler language
Pros and cons of c as a compiler languageAshok Raj
 
Compiler_Lecture1.pdf
Compiler_Lecture1.pdfCompiler_Lecture1.pdf
Compiler_Lecture1.pdfAkarTaher
 
Compiler Design Introduction
Compiler Design Introduction Compiler Design Introduction
Compiler Design Introduction Thapar Institute
 
Dineshmaterial1 091225091539-phpapp02
Dineshmaterial1 091225091539-phpapp02Dineshmaterial1 091225091539-phpapp02
Dineshmaterial1 091225091539-phpapp02Tirumala Rao
 
Compiler Design(Nanthu)
Compiler Design(Nanthu)Compiler Design(Nanthu)
Compiler Design(Nanthu)guest91cc85
 
Compilerdesignnew 091219090526-phpapp02
Compilerdesignnew 091219090526-phpapp02Compilerdesignnew 091219090526-phpapp02
Compilerdesignnew 091219090526-phpapp02Anil Thakral
 

Similar a unit1pdf__2021_12_14_12_37_34.pdf (20)

Chapter1pdf__2021_11_23_10_53_20.pdf
Chapter1pdf__2021_11_23_10_53_20.pdfChapter1pdf__2021_11_23_10_53_20.pdf
Chapter1pdf__2021_11_23_10_53_20.pdf
 
Chapter#01 cc
Chapter#01 ccChapter#01 cc
Chapter#01 cc
 
Phases of Compiler.pptx
Phases of Compiler.pptxPhases of Compiler.pptx
Phases of Compiler.pptx
 
Compiler Design Material
Compiler Design MaterialCompiler Design Material
Compiler Design Material
 
Chapter 1.pptx
Chapter 1.pptxChapter 1.pptx
Chapter 1.pptx
 
Assignment1
Assignment1Assignment1
Assignment1
 
Chapter 2 Program language translation.pptx
Chapter 2 Program language translation.pptxChapter 2 Program language translation.pptx
Chapter 2 Program language translation.pptx
 
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
 
How a Compiler Works ?
How a Compiler Works ?How a Compiler Works ?
How a Compiler Works ?
 
Chapter-1.pptx compiler Design Course Material
Chapter-1.pptx compiler Design Course MaterialChapter-1.pptx compiler Design Course Material
Chapter-1.pptx compiler Design Course Material
 
2-Design Issues, Patterns, Lexemes, Tokens-28-04-2023.docx
2-Design Issues, Patterns, Lexemes, Tokens-28-04-2023.docx2-Design Issues, Patterns, Lexemes, Tokens-28-04-2023.docx
2-Design Issues, Patterns, Lexemes, Tokens-28-04-2023.docx
 
Pros and cons of c as a compiler language
  Pros and cons of c as a compiler language  Pros and cons of c as a compiler language
Pros and cons of c as a compiler language
 
Compiler_Lecture1.pdf
Compiler_Lecture1.pdfCompiler_Lecture1.pdf
Compiler_Lecture1.pdf
 
Compiler Design Introduction
Compiler Design Introduction Compiler Design Introduction
Compiler Design Introduction
 
Cpcs302 1
Cpcs302  1Cpcs302  1
Cpcs302 1
 
Dineshmaterial1 091225091539-phpapp02
Dineshmaterial1 091225091539-phpapp02Dineshmaterial1 091225091539-phpapp02
Dineshmaterial1 091225091539-phpapp02
 
Phases of Compiler
Phases of CompilerPhases of Compiler
Phases of Compiler
 
Compiler Design(Nanthu)
Compiler Design(Nanthu)Compiler Design(Nanthu)
Compiler Design(Nanthu)
 
Compilerdesignnew 091219090526-phpapp02
Compilerdesignnew 091219090526-phpapp02Compilerdesignnew 091219090526-phpapp02
Compilerdesignnew 091219090526-phpapp02
 
Compiler Design
Compiler DesignCompiler Design
Compiler Design
 

Último

VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Bookingdharasingh5698
 
Double Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torqueDouble Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torqueBhangaleSonal
 
chapter 5.pptx: drainage and irrigation engineering
chapter 5.pptx: drainage and irrigation engineeringchapter 5.pptx: drainage and irrigation engineering
chapter 5.pptx: drainage and irrigation engineeringmulugeta48
 
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Call Girls in Nagpur High Profile
 
Bhosari ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready For ...
Bhosari ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready For ...Bhosari ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready For ...
Bhosari ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready For ...tanu pandey
 
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXssuser89054b
 
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance BookingCall Girls Wakad Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance Bookingroncy bisnoi
 
Intze Overhead Water Tank Design by Working Stress - IS Method.pdf
Intze Overhead Water Tank  Design by Working Stress - IS Method.pdfIntze Overhead Water Tank  Design by Working Stress - IS Method.pdf
Intze Overhead Water Tank Design by Working Stress - IS Method.pdfSuman Jyoti
 
University management System project report..pdf
University management System project report..pdfUniversity management System project report..pdf
University management System project report..pdfKamal Acharya
 
Work-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptxWork-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptxJuliansyahHarahap1
 
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordCCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordAsst.prof M.Gokilavani
 
Double rodded leveling 1 pdf activity 01
Double rodded leveling 1 pdf activity 01Double rodded leveling 1 pdf activity 01
Double rodded leveling 1 pdf activity 01KreezheaRecto
 
Intro To Electric Vehicles PDF Notes.pdf
Intro To Electric Vehicles PDF Notes.pdfIntro To Electric Vehicles PDF Notes.pdf
Intro To Electric Vehicles PDF Notes.pdfrs7054576148
 
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdfONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdfKamal Acharya
 
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...Call Girls in Nagpur High Profile
 
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Bookingdharasingh5698
 

Último (20)

VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
 
Double Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torqueDouble Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torque
 
chapter 5.pptx: drainage and irrigation engineering
chapter 5.pptx: drainage and irrigation engineeringchapter 5.pptx: drainage and irrigation engineering
chapter 5.pptx: drainage and irrigation engineering
 
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
 
Bhosari ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready For ...
Bhosari ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready For ...Bhosari ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready For ...
Bhosari ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready For ...
 
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
 
(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7
(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7
(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7
 
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
 
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance BookingCall Girls Wakad Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance Booking
 
Intze Overhead Water Tank Design by Working Stress - IS Method.pdf
Intze Overhead Water Tank  Design by Working Stress - IS Method.pdfIntze Overhead Water Tank  Design by Working Stress - IS Method.pdf
Intze Overhead Water Tank Design by Working Stress - IS Method.pdf
 
University management System project report..pdf
University management System project report..pdfUniversity management System project report..pdf
University management System project report..pdf
 
Work-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptxWork-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptx
 
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordCCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
 
Double rodded leveling 1 pdf activity 01
Double rodded leveling 1 pdf activity 01Double rodded leveling 1 pdf activity 01
Double rodded leveling 1 pdf activity 01
 
Call Girls in Netaji Nagar, Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Netaji Nagar, Delhi 💯 Call Us 🔝9953056974 🔝 Escort ServiceCall Girls in Netaji Nagar, Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Netaji Nagar, Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
 
NFPA 5000 2024 standard .
NFPA 5000 2024 standard                                  .NFPA 5000 2024 standard                                  .
NFPA 5000 2024 standard .
 
Intro To Electric Vehicles PDF Notes.pdf
Intro To Electric Vehicles PDF Notes.pdfIntro To Electric Vehicles PDF Notes.pdf
Intro To Electric Vehicles PDF Notes.pdf
 
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdfONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
 
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
 
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
 

unit1pdf__2021_12_14_12_37_34.pdf

  • 1. Department of CE / IT Prof. Dhara Joshi Unit no : 1 Introduction to Compiler (01CE0601) Introduction to Compiler CD:COMPILER DESIGN
  • 2. Department of CE / IT Prof. Dhara Joshi Unit no : 1 Introduction to Compiler (01CE0601) Outline : Translator Compiler, Interpreter, Assembler Cousins of Compiler Phases of Compiler Grouping of Phases Types of Compiler Compiler construction tools Pass and Phase
  • 5. Translator Translator : • A translator is a program which takes one program (written in one language) as input and converts it into another language (Target language). • Input Language is Source Language and Output Language is Target Language. • There are Three types of Translator : 1) Compiler 2) Interpreter 3) Assembler  It also detects and reports error during translation.
  • 6. Compiler Compiler :  Compiler is a program that reads a program written in one language that means source language and translates it into equivalent program into another language that is target language.  Compiler is a program which translates higher level language into functionally equivalent lower level language.  It also detects and reports error. Source Target Program Program Error Compiler
  • 7. Interpreter Interpreter :  Interpreter is a translator which is used to convert programs in high-level language to low-level language.  Interpreter translates line by line and reports the error once it encountered during the translation process. Source Target Program Program Error Interpreter
  • 8. Assembler Assembler :  An assembler is a translator used to translate assembly language to machine language.  An assembler translates a low-level language, an assembly language to an even lower-level language, which is the machine code. The machine code can be directly understood by the CPU. Source Target Program Program Error Assembler
  • 9. Compiler Vs Interpreter Compiler Interpreter It takes whole program as input It takes single instruction as input It generates intermediate object code It does not generate any intermediate object code Memory requirement is more due to creation of object code. Memory requirement is less (memory efficient) as it does not create intermediate object code. It takes large amount of time to analyze the source code but overall execution is comparatively faster. It takes less amount of time to analyze the source code but overall execution is slower. Compilation is done before execution. Compilation and execution take place simultaneously. Display all errors after entire program is checked. Display errors of each line one by one. Ex : C , C ++ Ex : BASIC , Python
  • 10. Compiler Vs Assembler Compiler Assembler Input for compiler is Pre processed Source code. Input for Assembler is Assembly language code. It generates assembly language code or directly the executable code. It generates the relocatable machine code. There are 6 Phases of compiler It makes Two passes over given input. Ex : C , C ++ Ex : 8085 , 8086
  • 11. Language Processing System / Translation Processor / Context of Compiler /Cousins of Compiler Pre Processor Compiler Assembler Linker & Loader HLL Pure HLL Assembly Language Relocatable Machine code Absolute Machine code Library , Relocatable object files
  • 12. Language Processing System / Translation Processor / Context of Compiler /Cousins of Compiler  There are three cousins of Compiler 1) Preprocessor 2) Assembler 3) Linker and Loader
  • 13. Language Processing System / Translation Processor / Context of Compiler /Cousins of Compiler 1) Preprocessor  Preprocessor produces input to compilers.  They may perform the following functions  Macro Processing : A preprocessor may allow a user to define macros that are short hands for longer constructs. File Inclusion : A preprocessor may include header files into program text. “Rational” Preprocessor : These processors augment older languages with more modern flow of control and data structuring facilities. (Built in Macro for construct like While or If Statement)  Language Extension : These processor attempt to add capabilities to the language by what amount to built in macros. the language equal is a database query language embedded in C. statement beginning with ## are taken by preprocessor to be database access statement unrelated to C and translated into procedure call on routines that perform database access.
  • 14. Language Processing System / Translation Processor / Context of Compiler /Cousins of Compiler 1) Preprocessor  Macro processor deal with two kinds of statement Macro Definition Macro Use  Formal Parameters  Actual Parameters
  • 15. Language Processing System / Translation Processor / Context of Compiler /Cousins of Compiler 2) Assembler  An assembler is a translator used to translate assembly language to machine language.  An assembler translates a low-level language, an assembly language to an even lower-level language, which is the machine code. The machine code can be directly understood by the CPU. Source Target Program Program Error Assembler
  • 16. Language Processing System / Translation Processor / Context of Compiler /Cousins of Compiler 2) Assembler  Assembly code is mnemonic version of machine code, in which names are used instead of binary codes for operation and names are also given to memory address.
  • 17. Language Processing System / Translation Processor / Context of Compiler /Cousins of Compiler 3) Linker and Loader  A program called loader performs the two functions of loading and link editing  The process of loading consist of taking relocatable machine code , altering the relocatable address and placing the altered instructions and data in memory at the proper location.  Linker allows us to make a single program from several files of relocatable machine code.  Types of Linking : Static and Dynamic  Types of Loader : Compile and Go loader, Absolute Loader, Relocating Loader.
  • 19. Phases of Compiler / Analysis – Synthesis Model of Compilation 1) Lexical Analysis  It is also called Linear analysis or scanning.  In this phase, input character from source code is read from left to right and then break into stream of units. These units are called tokens.  Sequence of characters having a collective meaning is called Token.  Tokens can be categorized into identifiers, constants, literals, keywords, operators, delimeters etc.  So, Token is the smallest meaningful entities of program are produced as output.
  • 20. Phases of Compiler / Analysis – Synthesis Model of Compilation 1) Lexical Analysis Example : position = initial + rate * 60 id1 = id2 + id3 * 60 Position Identifier 1 = Equal to operator Initial Identifier 2 + Addition Operator Rate Identifier 3 * Multiplication Operator 60 Constant
  • 22. Phases of Compiler / Analysis – Synthesis Model of Compilation 2) Syntax Analysis  It is also called Hierarchical analysis or Parsing.  It determines if the sentence formed from the words are syntactically (grammatically) correct.  It creates syntax tree from generated tokens if the code is error free.  Syntax tree consist operators as internal node and operands as leaf node.  This phase check each and every line and try to detect errors if it is grammatically (syntax wise) not correct.
  • 23. Phases of Compiler / Analysis – Synthesis Model of Compilation 2) Syntax Analysis position = initial + rate * 60 Three Operators : = + * position = initial + rate * 60 position = initial + rate * 60 position = initial + rate * 60
  • 24. Phases of Compiler Lexical Analyzer Syntax Analyzer Semantic Analyzer
  • 25. Phases of Compiler / Analysis – Synthesis Model of Compilation 3) Semantic Analysis  It determines meaning of string  In semantic analysis various operations are performed like  Performing check ; whether operator have compatible arguments or not (type checking) , matching of parenthesis, scope of operation etc.  Ensuring that components of a program fits together meaningfully.
  • 26. Phases of Compiler / Analysis – Synthesis Model of Compilation 3) Semantic Analysis position = initial + rate * 60
  • 27. Phases of Compiler Lexical Analyzer Syntax Analyzer Semantic Analyzer Intermediate Code Generator
  • 28. Phases of Compiler / Analysis – Synthesis Model of Compilation 4) Intermediate Code Generator  Intermediate code generation should have two properties : it should be easy to produce, easy to translate.  Intermediate code is called “Three Address Code”.  It is called three address code as it maximum consist three operands.
  • 29. Phases of Compiler / Analysis – Synthesis Model of Compilation 4) Intermediate Code Generator Example : position = initial + rate * 60 t1 = inttoreal(60) t2 = rate * t1 t3 = initial + t2 position = t3
  • 30. Phases of Compiler Lexical Analyzer Syntax Analyzer Semantic Analyzer Intermediate Code Generator Code Optimizer
  • 31. Phases of Compiler / Analysis – Synthesis Model of Compilation 5) Code Optimization  This phase improves the intermediate code, in such a way that a machine code can be produced, which occupies less memory space and less execution time without changing the functionality or correctness of program.  Example : t1 = rate * 60.00 position = initial + t1
  • 32. Phases of Compiler Lexical Analyzer Syntax Analyzer Semantic Analyzer Intermediate Code Generator Code Optimizer Code Generator
  • 33. Phases of Compiler / Analysis – Synthesis Model of Compilation 6) Code Generation  In Code generation phase the target code gets generated.  In this phase intermediate (optimized) code is translated into a sequence of machine instructions that perform the same operation.  Example : MOVF id3,R1 MULF #60.00, R1 MOVF id2, R2 ADDF R2, R1 MOVF R1, id1 position = initial + rate * 60 id 1 id2 id3 R1 = id3 (rate) R1 = 60.00 * R1 R2 = id2 (initial) R1 = R2 + R1 id1(position) = R1
  • 34. Phases of Compiler Lexical Analyzer Syntax Analyzer Semantic Analyzer Intermediate Code Generator Code Optimizer Code Generator Symbol Table Manager Error handler
  • 35. Phases of Compiler Lexical Analyzer Syntax Analyzer Semantic Analyzer Intermediate Code Generator Code Optimizer Code Generator Symbol Table Manager Error handler Analysis Phase Synthesis Phase
  • 36. Phases of Compiler / Analysis – Synthesis Model of Compilation  There are two parts of Compilation Process : 1) Analysis Phase It breaks up source program into small pieces and create an intermediate representation of source program. 2) Synthesis Phase It constructs the desired target program from intermediate representation.
  • 37. Phases of Compiler / Analysis – Synthesis Model of Compilation 1) Analysis Phase Consist of Three Sub Phases :  Lexical analysis  Syntax analysis  Semantic analysis 2) Synthesis Phase : Consist of Three Sub Phases :  Intermediate Code generation  Code Optimization  Code Generation
  • 38. Phases of Compiler / Analysis – Synthesis Model of Compilation Symbol Table :  A symbol table is data structure used by language translators.  In order to keep track of identifiers used by program, compiler maintains the record of the same with their various attributes.  Symbol table stores information for different entities : Identifier, Function, Procedure, Constant , Label Name, Compiler generated temporaries etc.
  • 39. Phases of Compiler / Analysis – Synthesis Model of Compilation Error Detection and Recovery :  Each phase can encounter errors, However after detecting an error a phase must some how deal with that error. So that Compilation can proceed, allowing further errors in the source program to be detected.  Lexical Analyzer can detect errors where the character remaining in the input do not form any token of the language.  Errors where the token stream violates the structure rule (syntax) of the language are determined by syntax analysis phase.  During Semantic analysis, the compiler tries to detect constructs that have the right syntactic structure but no meaning to the operation involved.
  • 40. Phases of Compiler / Analysis – Synthesis Model of Compilation Lexical analyzer Syntax analyzer Semantic analyzer a=b+c*60 Id1=id2+id3*60 = + * 60 id1 id2 id3 = + * 60 id1 id2 id3 Int to float Intermediate code generator t1:= inttofloat (60) t2:= id3 * t1 t3:= id2 + t2 id1:= t3 Code optimizer t1:= id3 * 60.0 id1:= id2 + t1 Code generator MOVEF id3, R2 MULF #60.0,R2 MOVF id2, R1 ADDF R2,R1 MOVF R1,id1
  • 41. Practice Time Example : What will be the output of each phase for the following statement? Statement : x = a + b * c
  • 42. Grouping of Phases Front End • Dependent : Source Language • Independent : Target Machine Back End • Dependent : Target Machine • Independent : Source Language
  • 43. Grouping of Phases Front End:  Front end consist of those phase, that depends preliminary on the source language & are independent of the target machine.  It includes Lexical analysis, Syntax analysis, Semantic analysis, Intermediate code generation and Creation of Symbol table.  A certain amount of code optimization can be done by the front end as well  The front end also includes error handling that goes along with each of these phases.
  • 44. Grouping of Phases Back End:  Back includes those portion of compiler that depend on the target machine and do not depend on source language.  Back end includes code optimization and code generation with necessary error handling and symbol table operation. It has become fairly routine to take front end of a compiler & redo its back end to produce a compiler for the same source language on a different machine.
  • 45. Pass of Compiler  One Complete scan of Source program is called Pass.  Difficulty in single pass :  Forward Reference : A forward reference means variable or label is referenced before its declared.  It leads to Multi-Pass model. Pass – 1 : Perform analysis of source program and note relevant information Pass – 2 : Generate target code using information noted in pass-1. START 100 (AD,01) (C,200) READ A (IS,09) (S,01) LOOP MOVER AREG , A .............. ........ ............... ........ ............... BC GT , LOOP ............... STOP (IS , 00) A DS 1 (DL,02) (C,1) .......
  • 46. Pass Vs Phase Pass Phase Various phases are logically grouped together to form a pass. The process of compilation is carried out in various step is called Phase. Require Less Memory Require More Memory Execution is faster Execution is slower Less memory operation(read/write) to be performed More memory operations to be performed 2 Passes of Compiler 6 Phases of Compiler
  • 47. Types of Compiler Native Compiler Cross Compiler Source to Source Compiler Just inTime Compiler Incremental Compiler Parallelizing Compiler
  • 48. Types of Compiler Native Compiler :  The compiler used to Compile a source code for same type of platform only.  The output generated by this type of compiler can only be run on the same type of computer system and OS that the compiler itself runs on. Cross Compiler :  The compiler used to compile a source code for different kinds platform.  A Cross compiler is a compiler capable of creating executable code for a platform other than one on which compiler is running.
  • 49. Types of Compiler Source to Source Compiler :  The compiler that takes high-level language code as input and outputs source code of another high- level language only.  Unlike other compilers which convert high level language into low level machine language, it can take up a code written in Pascal and can transform it into C-conversion of one high level language into another high level language having same type of abstraction .  Thus, it is also known as transpiler .
  • 50. Types of Compiler Just in Time Compiler :  The compiler which converts a code into machine code after the program starts execution.  Convert .java file into .class file.
  • 51. Types of Compiler Incremental Compiler :  The compiler which compiles only the changed lines from the source code and update the object code. Parallelizing Compiler :  A Compiler which is specially designed to run in parallel computer architecture is known as parallelizing compiler. int a=0; int b=1; printf("Enter Input"); Scanf(); if(a==10) printf();
  • 52. Compiler Construction Tools Compiler Construction Tools : 1) Scanner Generators 2) Parser Generators 3) Syntax – directed translation engines 4) Automatic Code Generators 5) Data Flow Engine
  • 53. Compiler Construction Tools Scanner generators: This tool takes regular expressions as input. For example LEX for Unix Operating System. Parser generators: A parser generator takes a grammar as input and automatically generates source code which can parse streams of characters with the help of a grammar Syntax-directed translation engines: These software tools offer an intermediate code by using the parse tree. It has a goal of associating one or more translations with each node of the parse tree. Automatic code generators: Takes intermediate code and converts them into Machine Language Data-flow engines: This tool is helpful for code optimization. Here, information is supplied by user and intermediate code is compared to analyze any relation. It is also known as data-flow analysis. It helps you to find out how values are transmitted from one part of the program to another part.
  • 54. Qualities of Compiler  Compiler itself must be bug free.  It must generate correct machine code.  Generated machine code must run fast (Execution speed).  Compilation time must be less.  Compilation must be portable.  It must be print good diagnostics and Error message.  Generated code must work well with existing debugger.  It must have consistent and Predictable optimization.
  • 55. References 1. Aho, Lam, Sethi, and Ullman, Compilers: Principles, Techniques and Tools,SecondEdition, Pearson, 2014 2. D. M. Dhamdhere: Systerm Programming, Mc Graw Hill Publication 3. Dick Grune, Henri E. Bal, Jacob, Langendoen: Modern Compiler Design, Wiley India Publication
  • 56. MU Questions 1) Develop Analysis – Synthesis model of Compiler for a = b + c * 20. Write down explanation and output for each phase of compiler. 2) Difference between Compiler and Interpreter. 3) Explain Cousins of compiler. 4) Give the name of Front End and Back End with explanation, and take one example to show the output of the every phase.
  • 57. Department of CE / IT Prof. Dhara Joshi Unit no : 1 Introduction to Compiler (01CE0601) Thanks