SlideShare a Scribd company logo
1 of 22
By
Abhishek Singh
Computer Sc. Department
 Introduction to Translator.
 Assembler.
 Interpreter.
 Compiler.
 Phases of Compiler.
 Example
Created By Abhishek Singh 2
 Translator is system software which translate source
language into target language.
 Translator are of three type:-
Assembler.
Interpreter.
Compiler.
Created By Abhishek Singh 3
 Assembler translates an assembly language program
(the source program) to the machine language
program (the object program).
 Assembly language use Mnemonics like ADD,MULT
etc.
 Form example:- MOV R1,a
Created By
Abhishek Singh 4
Assembler
Assembly
Language
Machine
Language
 Interpreter translates a program line-by-line
(statement-by-statement) and carries out the specified
actions according to input.
Created By Abhishek Singh 5
Interpreter
Source
Program
Input
Output
Error messages
 Compiler is a system software, which translates a
program written in a source language into an
equivalent program in a target language.
Created By Abhishek Singh 6
Compiler
Error messages
Source
Program
Target
Program
Input
Output
 Compiler have six phase.
1. Lexical Analysis.
2. Syntax Analysis.
3. Semantic Analysis.
4. Intermediate Code Generation.
5. Code Optimization.
6. Code Generation.
Created By Abhishek Singh 7
 In this phase of compilation full source code is
scanned and program is broken up into groups of
string called token.
 Token is a sequence of characters having a collective
meaning.
 For example:-
◦ total = count + rate * 10
Created By Abhishek Singh 8
total = count + rate * 10
 In this phase token generated by lexical analyses are
grouped together to form a hierarchical structure.
 The structure is known syntax tree. For building
syntax tree the production rules are designed. These
rule are according to Grammar.
 Let take Grammar for total = count + rate * 10
 E<- id
 E<-number
 E<-E1 + E2
 E<-E1 * E2
 E<-(E)
Created By Abhishek Singh 9
Created By Abhishek Singh 10
total
=
+
*count
rate 10
 Semantic analysis is a phase of compiler that adds
semantical information to the parse tree and performs
certain checks based on this information.
 For a program to be semantically valid mean, all
variables, functions, classes, etc. must be properly
defined.
Created By Abhishek Singh 11
Created By Abhishek Singh 12
total
=
+
*count
rate int to real
10
 This is a kind of code which is easy to generate and easily
converted to target code.
 This code is in form like three address code.
 For example
 Intermediate for total = count + rate * 10
 Here t1,t2 and t3 are temporary variable.
 t1 := int to real (10)
 t2 := rate * t1
 t3 := count + t2
 total := t3
Created By Abhishek Singh 13
 The code optimization phase attempts to improve the
intermediate code, this phase increase the execution
speed and less consumption of memory.
◦ Optimize code for code total = count + rate * 10 is
 t1 := rate * 10.0
 total := count + t1
Created By Abhishek Singh 14
 In this phase target code gets generated. The code
optimization phase instructions are translated into
sequence of target code.
 Generated code is:-
◦ MOV R1,rate
◦ MUL R1,10.0
◦ MOV R2, count
◦ ADD R1,R2
◦ MOV total,R1
Created By Abhishek Singh 15
 The main utility of a compiler is to record the
variable names used in the source program and gather
information about different attributes of each
variable.
 These attributes can provide the information about
the storage allocation for name, its type, its scope
(where we use this value in program), and in the case
of function or subprogram, its name, number and
types of its arguments, the method of passing each
argument (like, by value or by reference), and the
type returns.
Created By Abhishek Singh 16
 Mainly compilation error are gather in:-
1. Lexical Errors :-Lexical phase detect errors of inputs
such as illegal characters , End of line mark missing in
strings.
2. Syntactical Errors :- Syntactical phase detect errors of
syntax like, Incorrect sequence of tokens, Misspelled
keywords (e.g. TEHN).
3. Semantical Errors :-Semantical phase detect errors of
meaning like, Incorrect composition of types,
Multiple declaration of a variable and Variable use
before assignment.
Created By Abhishek Singh 17
Created By Abhishek Singh 18
Lexical Analysis
Syntax Analysis
Semantic Analysis
Source Program
Total=count + rate* 10;
Token
stream total = count + rate * 10
=
total +
*count
rate 10
Syntax
Tree
Semantic
Tree
total
=
+
*count
rate int to real
10
Created By Abhishek Singh 19
Intermediate Code
Generation
Code Optimization
Code Generation
10
total
=
+
*count
rate int to real
t1 := int to real (10)
t2 := rate * t1
t3 := count + t2
total := t3
Semantic
Tree
Intermediate
Code
Target
Code
Optimize
Code t1 := rate * 10
total := count + t1
MOV rate,R1
MUL #10.0, R1
MOV count, R2
ADD R2,R1
MOV R1,total
Created By Abhishek Singh 20
Editor Compiler Assembler
Linker
LoaderDebugger
Programmer
Source
Program
Assembly
Code
Machine
Code
Linking
Programmer
Does manual
Correction of
the code
Debugging
Results
Debug if Error
Executable
Image
Created By Abhishek Singh 21
Created By Abhishek Singh 22

More Related Content

What's hot

Introduction to Compiler Construction
Introduction to Compiler Construction Introduction to Compiler Construction
Introduction to Compiler Construction Sarmad Ali
 
Syntax Analysis in Compiler Design
Syntax Analysis in Compiler Design Syntax Analysis in Compiler Design
Syntax Analysis in Compiler Design MAHASREEM
 
Three address code In Compiler Design
Three address code In Compiler DesignThree address code In Compiler Design
Three address code In Compiler DesignShine Raj
 
Symbol table in compiler Design
Symbol table in compiler DesignSymbol table in compiler Design
Symbol table in compiler DesignKuppusamy P
 
Lexical Analysis
Lexical AnalysisLexical Analysis
Lexical AnalysisNayemid4676
 
12-Syntax Directed Definition – Evaluation Order-09-06-2023.ppt
12-Syntax Directed Definition – Evaluation Order-09-06-2023.ppt12-Syntax Directed Definition – Evaluation Order-09-06-2023.ppt
12-Syntax Directed Definition – Evaluation Order-09-06-2023.pptvenkatapranaykumarGa
 
Parsing in Compiler Design
Parsing in Compiler DesignParsing in Compiler Design
Parsing in Compiler DesignAkhil Kaushik
 
Compiler Construction Course - Introduction
Compiler Construction Course - IntroductionCompiler Construction Course - Introduction
Compiler Construction Course - IntroductionMuhammad Sanaullah
 
Passes of compilers
Passes of compilersPasses of compilers
Passes of compilersVairavel C
 
Compiler Construction introduction
Compiler Construction introductionCompiler Construction introduction
Compiler Construction introductionRana Ehtisham Ul Haq
 
Compiler construction tools
Compiler construction toolsCompiler construction tools
Compiler construction toolsAkhil Kaushik
 

What's hot (20)

Introduction to Compiler Construction
Introduction to Compiler Construction Introduction to Compiler Construction
Introduction to Compiler Construction
 
Syntax Analysis in Compiler Design
Syntax Analysis in Compiler Design Syntax Analysis in Compiler Design
Syntax Analysis in Compiler Design
 
Syntax analysis
Syntax analysisSyntax analysis
Syntax analysis
 
Three address code In Compiler Design
Three address code In Compiler DesignThree address code In Compiler Design
Three address code In Compiler Design
 
Symbol table in compiler Design
Symbol table in compiler DesignSymbol table in compiler Design
Symbol table in compiler Design
 
Compiler lec 8
Compiler lec 8Compiler lec 8
Compiler lec 8
 
Compiler Construction
Compiler ConstructionCompiler Construction
Compiler Construction
 
Lexical Analysis
Lexical AnalysisLexical Analysis
Lexical Analysis
 
Top down parsing
Top down parsingTop down parsing
Top down parsing
 
12-Syntax Directed Definition – Evaluation Order-09-06-2023.ppt
12-Syntax Directed Definition – Evaluation Order-09-06-2023.ppt12-Syntax Directed Definition – Evaluation Order-09-06-2023.ppt
12-Syntax Directed Definition – Evaluation Order-09-06-2023.ppt
 
Introduction to Compiler
Introduction to CompilerIntroduction to Compiler
Introduction to Compiler
 
Input-Buffering
Input-BufferingInput-Buffering
Input-Buffering
 
Parsing in Compiler Design
Parsing in Compiler DesignParsing in Compiler Design
Parsing in Compiler Design
 
Compiler Construction Course - Introduction
Compiler Construction Course - IntroductionCompiler Construction Course - Introduction
Compiler Construction Course - Introduction
 
Passes of compilers
Passes of compilersPasses of compilers
Passes of compilers
 
Parsing LL(1), SLR, LR(1)
Parsing LL(1), SLR, LR(1)Parsing LL(1), SLR, LR(1)
Parsing LL(1), SLR, LR(1)
 
Lexical analyzer
Lexical analyzerLexical analyzer
Lexical analyzer
 
Compiler Construction introduction
Compiler Construction introductionCompiler Construction introduction
Compiler Construction introduction
 
Top down parsing
Top down parsingTop down parsing
Top down parsing
 
Compiler construction tools
Compiler construction toolsCompiler construction tools
Compiler construction tools
 

Similar to Basic of compiler

unit1pdf__2021_12_14_12_37_34.pdf
unit1pdf__2021_12_14_12_37_34.pdfunit1pdf__2021_12_14_12_37_34.pdf
unit1pdf__2021_12_14_12_37_34.pdfDrIsikoIsaac
 
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
 
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
 
Concept of compiler in details
Concept of compiler in detailsConcept of compiler in details
Concept of compiler in detailskazi_aihtesham
 
1 - Introduction to Compilers.ppt
1 - Introduction to Compilers.ppt1 - Introduction to Compilers.ppt
1 - Introduction to Compilers.pptRakesh Kumar
 
Chapter One
Chapter OneChapter One
Chapter Onebolovv
 
Introduction to Compilers
Introduction to CompilersIntroduction to Compilers
Introduction to Compilersvijaya603274
 
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
 
Phases of Compiler.pptx
Phases of Compiler.pptxPhases of Compiler.pptx
Phases of Compiler.pptxssuser3b4934
 
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
 

Similar to Basic of compiler (20)

unit1pdf__2021_12_14_12_37_34.pdf
unit1pdf__2021_12_14_12_37_34.pdfunit1pdf__2021_12_14_12_37_34.pdf
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.pdf
 
Compiler
Compiler Compiler
Compiler
 
Chapter#01 cc
Chapter#01 ccChapter#01 cc
Chapter#01 cc
 
How a Compiler Works ?
How a Compiler Works ?How a Compiler Works ?
How a Compiler Works ?
 
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
 
Concept of compiler in details
Concept of compiler in detailsConcept of compiler in details
Concept of compiler in details
 
3.2
3.23.2
3.2
 
Compiler Design
Compiler DesignCompiler Design
Compiler Design
 
1 - Introduction to Compilers.ppt
1 - Introduction to Compilers.ppt1 - Introduction to Compilers.ppt
1 - Introduction to Compilers.ppt
 
Assignment1
Assignment1Assignment1
Assignment1
 
Phases of compiler
Phases of compilerPhases of compiler
Phases of compiler
 
Chapter One
Chapter OneChapter One
Chapter One
 
Introduction to Compilers
Introduction to CompilersIntroduction to Compilers
Introduction to Compilers
 
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
 
Phases of Compiler.pptx
Phases of Compiler.pptxPhases of Compiler.pptx
Phases of Compiler.pptx
 
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
 
The Phases of a Compiler
The Phases of a CompilerThe Phases of a Compiler
The Phases of a Compiler
 
PPT
PPTPPT
PPT
 
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
 

Recently uploaded

High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
chaitra-1.pptx fake news detection using machine learning
chaitra-1.pptx  fake news detection using machine learningchaitra-1.pptx  fake news detection using machine learning
chaitra-1.pptx fake news detection using machine learningmisbanausheenparvam
 
Current Transformer Drawing and GTP for MSETCL
Current Transformer Drawing and GTP for MSETCLCurrent Transformer Drawing and GTP for MSETCL
Current Transformer Drawing and GTP for MSETCLDeelipZope
 
HARMONY IN THE HUMAN BEING - Unit-II UHV-2
HARMONY IN THE HUMAN BEING - Unit-II UHV-2HARMONY IN THE HUMAN BEING - Unit-II UHV-2
HARMONY IN THE HUMAN BEING - Unit-II UHV-2RajaP95
 
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdfCCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdfAsst.prof M.Gokilavani
 
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...srsj9000
 
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...Soham Mondal
 
Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...VICTOR MAESTRE RAMIREZ
 
What are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxWhat are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxwendy cai
 
Artificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptxArtificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptxbritheesh05
 
Application of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptxApplication of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptx959SahilShah
 
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerStudy on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerAnamika Sarkar
 
Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024hassan khalil
 
ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...
ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...
ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...ZTE
 
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...VICTOR MAESTRE RAMIREZ
 

Recently uploaded (20)

High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
chaitra-1.pptx fake news detection using machine learning
chaitra-1.pptx  fake news detection using machine learningchaitra-1.pptx  fake news detection using machine learning
chaitra-1.pptx fake news detection using machine learning
 
Current Transformer Drawing and GTP for MSETCL
Current Transformer Drawing and GTP for MSETCLCurrent Transformer Drawing and GTP for MSETCL
Current Transformer Drawing and GTP for MSETCL
 
HARMONY IN THE HUMAN BEING - Unit-II UHV-2
HARMONY IN THE HUMAN BEING - Unit-II UHV-2HARMONY IN THE HUMAN BEING - Unit-II UHV-2
HARMONY IN THE HUMAN BEING - Unit-II UHV-2
 
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptxExploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
 
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdfCCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
 
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
 
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
 
Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...
 
What are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxWhat are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptx
 
Artificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptxArtificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptx
 
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
 
Application of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptxApplication of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptx
 
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
 
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCRCall Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
 
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerStudy on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
 
Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024
 
ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...
ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...
ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...
 
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
 

Basic of compiler

  • 2.  Introduction to Translator.  Assembler.  Interpreter.  Compiler.  Phases of Compiler.  Example Created By Abhishek Singh 2
  • 3.  Translator is system software which translate source language into target language.  Translator are of three type:- Assembler. Interpreter. Compiler. Created By Abhishek Singh 3
  • 4.  Assembler translates an assembly language program (the source program) to the machine language program (the object program).  Assembly language use Mnemonics like ADD,MULT etc.  Form example:- MOV R1,a Created By Abhishek Singh 4 Assembler Assembly Language Machine Language
  • 5.  Interpreter translates a program line-by-line (statement-by-statement) and carries out the specified actions according to input. Created By Abhishek Singh 5 Interpreter Source Program Input Output Error messages
  • 6.  Compiler is a system software, which translates a program written in a source language into an equivalent program in a target language. Created By Abhishek Singh 6 Compiler Error messages Source Program Target Program Input Output
  • 7.  Compiler have six phase. 1. Lexical Analysis. 2. Syntax Analysis. 3. Semantic Analysis. 4. Intermediate Code Generation. 5. Code Optimization. 6. Code Generation. Created By Abhishek Singh 7
  • 8.  In this phase of compilation full source code is scanned and program is broken up into groups of string called token.  Token is a sequence of characters having a collective meaning.  For example:- ◦ total = count + rate * 10 Created By Abhishek Singh 8 total = count + rate * 10
  • 9.  In this phase token generated by lexical analyses are grouped together to form a hierarchical structure.  The structure is known syntax tree. For building syntax tree the production rules are designed. These rule are according to Grammar.  Let take Grammar for total = count + rate * 10  E<- id  E<-number  E<-E1 + E2  E<-E1 * E2  E<-(E) Created By Abhishek Singh 9
  • 10. Created By Abhishek Singh 10 total = + *count rate 10
  • 11.  Semantic analysis is a phase of compiler that adds semantical information to the parse tree and performs certain checks based on this information.  For a program to be semantically valid mean, all variables, functions, classes, etc. must be properly defined. Created By Abhishek Singh 11
  • 12. Created By Abhishek Singh 12 total = + *count rate int to real 10
  • 13.  This is a kind of code which is easy to generate and easily converted to target code.  This code is in form like three address code.  For example  Intermediate for total = count + rate * 10  Here t1,t2 and t3 are temporary variable.  t1 := int to real (10)  t2 := rate * t1  t3 := count + t2  total := t3 Created By Abhishek Singh 13
  • 14.  The code optimization phase attempts to improve the intermediate code, this phase increase the execution speed and less consumption of memory. ◦ Optimize code for code total = count + rate * 10 is  t1 := rate * 10.0  total := count + t1 Created By Abhishek Singh 14
  • 15.  In this phase target code gets generated. The code optimization phase instructions are translated into sequence of target code.  Generated code is:- ◦ MOV R1,rate ◦ MUL R1,10.0 ◦ MOV R2, count ◦ ADD R1,R2 ◦ MOV total,R1 Created By Abhishek Singh 15
  • 16.  The main utility of a compiler is to record the variable names used in the source program and gather information about different attributes of each variable.  These attributes can provide the information about the storage allocation for name, its type, its scope (where we use this value in program), and in the case of function or subprogram, its name, number and types of its arguments, the method of passing each argument (like, by value or by reference), and the type returns. Created By Abhishek Singh 16
  • 17.  Mainly compilation error are gather in:- 1. Lexical Errors :-Lexical phase detect errors of inputs such as illegal characters , End of line mark missing in strings. 2. Syntactical Errors :- Syntactical phase detect errors of syntax like, Incorrect sequence of tokens, Misspelled keywords (e.g. TEHN). 3. Semantical Errors :-Semantical phase detect errors of meaning like, Incorrect composition of types, Multiple declaration of a variable and Variable use before assignment. Created By Abhishek Singh 17
  • 18. Created By Abhishek Singh 18 Lexical Analysis Syntax Analysis Semantic Analysis Source Program Total=count + rate* 10; Token stream total = count + rate * 10 = total + *count rate 10 Syntax Tree Semantic Tree total = + *count rate int to real 10
  • 19. Created By Abhishek Singh 19 Intermediate Code Generation Code Optimization Code Generation 10 total = + *count rate int to real t1 := int to real (10) t2 := rate * t1 t3 := count + t2 total := t3 Semantic Tree Intermediate Code Target Code Optimize Code t1 := rate * 10 total := count + t1 MOV rate,R1 MUL #10.0, R1 MOV count, R2 ADD R2,R1 MOV R1,total
  • 20. Created By Abhishek Singh 20 Editor Compiler Assembler Linker LoaderDebugger Programmer Source Program Assembly Code Machine Code Linking Programmer Does manual Correction of the code Debugging Results Debug if Error Executable Image