SlideShare a Scribd company logo
1 of 6
Introduction to Techniques and Applications of
Compiler Design
By,
R.Preethi M.Sc.,
Introduction to Techniques and Applications of Complier Design
What is Compiler?
A compiler is a program takes a program written in a source language and translates it
into an equivalent program in a target language.
Major Parts of Compilers
There are two major parts of a compiler:
Analysis Phase
In analysis phase, an intermediate representation is created from the given source
program. – Lexical Analyzer, Syntax Analyzer and Semantic Analyzer are the parts of
this phase.
Synthesis Phase
In synthesis phase, the equivalent target program is created from this intermediate
representation. – Intermediate Code Generator, Code Generator, and Code Optimizer are
the parts of this phase.
Phases of A Compiler
• Each phase transforms the source program from one representation into another
representation.
• They communicate with error handlers.
• They communicate with the symbol table.
Lexical Analyzer
• Lexical Analyzer reads the source program character by character and returns the tokens
of the source program.
• A token describes a pattern of characters having same meaning in the source program.
(such as identifiers, operators, keywords, numbers, delimeters and so on)
Ex: newval := oldval + 12 => tokens: newval identifier
:= assignment operator
oldval identifier
+ add operator
12 a number
• Puts information about identifiers into the symbol table.
• Regular expressions are used to describe tokens (lexical constructs).
• A (Deterministic) Finite State Automaton can be used in the implementation of a lexical
analyzer.
Syntax Analyzer
• A Syntax Analyzer creates the syntactic structure (generally a parse tree) of the given
program.
• A syntax analyzer is also called as a parser.
• A parse tree describes a syntactic structure.
assgstmt
identifier := expression
newval expression + expression
identifier number
oldval 12
Parsing Techniques
• The parsing techniques are categorized into two groups:
 Top-Down Parsing,
 Bottom-Up Parsing
• Top-Down Parsing:
 Construction of the parse tree starts at the root, and proceeds towards the leaves.
 Efficient top-down parsers can be easily constructed by hand.
 Recursive Predictive Parsing, Non-Recursive Predictive Parsing (LL Parsing).
• Bottom-Up Parsing:
 Construction of the parse tree starts at the leaves, and proceeds towards the root.
 Normally efficient bottom-up parsers are created with the help of some software
tools.
 Bottom-up parsing is also known as shift-reduce parsing.
 Operator-Precedence Parsing – simple, restrictive, easy to implement
 LR Parsing – much general form of shift-reduce parsing, LR, SLR, LALR
Semantic Analyzer
• A semantic analyzer checks the source program for semantic errors and collects the type
information for the code generation.
• Type-checking is an important part of semantic analyzer.
• Normally semantic information cannot be represented by a context-free language used in
syntax analyzers.
• Context-free grammars used in the syntax analysis are integrated with attributes
(semantic rules)
– the result is a syntax-directed translation,
– Attribute grammars
• Ex:
newval := oldval + 12
Intermediate Code Generation
• A compiler may produce an explicit intermediate codes representing the source program.
• These intermediate codes are generally machine (architecture independent). But the level
of intermediate codes is close to the level of machine codes.
• Ex:
newval := oldval * fact + 1
id1 := id2 * id3 + 1
MULT id2,id3,temp1 Intermediates Codes (Quadraples)
ADD temp1,#1,temp2
MOV temp2,,id1
Code Optimizer
• The code optimizer optimizes the code produced by the intermediate code generator in
the terms of time and space.
• Ex:
MULT id2, id3,temp1
ADD temp1,#1,id1
Code Generator
• Produces the target language in a specific architecture.
• The target program is normally is a relocatable object file containing the machine codes.
• Ex:
MOVEid2,R1
MULT id3,R1
ADD #1,R1
MOVER1,id1
Applications
In addition to the development of a compiler, the techniques used in compiler design can
be applicable to many problems in computer science.
 Techniques used in a lexical analyzer can be used in text editors, information
retrieval system, and pattern recognition programs.
 Techniques used in a parser can be used in a query processing system such as
SQL.
 Many software having a complex front-end may need techniques used in
compiler design.
Most of the techniques used in compiler design can be used in Natural Language
Processing (NLP) systems
Conclusion
These are the basic techniques of a compiler design and applications of compiler design
in computer science apart from the purpose of a compiler.

More Related Content

What's hot

Compiler Design
Compiler DesignCompiler Design
Compiler Design
Mir Majid
 

What's hot (20)

1.Role lexical Analyzer
1.Role lexical Analyzer1.Role lexical Analyzer
1.Role lexical Analyzer
 
Lexical analysis - Compiler Design
Lexical analysis - Compiler DesignLexical analysis - Compiler Design
Lexical analysis - Compiler Design
 
Phases of compiler
Phases of compilerPhases of compiler
Phases of compiler
 
Chomsky classification of Language
Chomsky classification of LanguageChomsky classification of Language
Chomsky classification of Language
 
Finite Automata
Finite AutomataFinite Automata
Finite Automata
 
Compiler construction tools
Compiler construction toolsCompiler construction tools
Compiler construction tools
 
Token, Pattern and Lexeme
Token, Pattern and LexemeToken, Pattern and Lexeme
Token, Pattern and Lexeme
 
Specification-of-tokens
Specification-of-tokensSpecification-of-tokens
Specification-of-tokens
 
Passes of compilers
Passes of compilersPasses of compilers
Passes of compilers
 
Relationship Among Token, Lexeme & Pattern
Relationship Among Token, Lexeme & PatternRelationship Among Token, Lexeme & Pattern
Relationship Among Token, Lexeme & Pattern
 
Compiler Design
Compiler DesignCompiler Design
Compiler Design
 
Lexical Analysis - Compiler Design
Lexical Analysis - Compiler DesignLexical Analysis - Compiler Design
Lexical Analysis - Compiler Design
 
Parsing
ParsingParsing
Parsing
 
Syntax Analysis in Compiler Design
Syntax Analysis in Compiler Design Syntax Analysis in Compiler Design
Syntax Analysis in Compiler Design
 
Types of Compilers
Types of CompilersTypes of Compilers
Types of Compilers
 
Text Editor in System software
Text Editor in System softwareText Editor in System software
Text Editor in System software
 
Type Checking(Compiler Design) #ShareThisIfYouLike
Type Checking(Compiler Design) #ShareThisIfYouLikeType Checking(Compiler Design) #ShareThisIfYouLike
Type Checking(Compiler Design) #ShareThisIfYouLike
 
Role-of-lexical-analysis
Role-of-lexical-analysisRole-of-lexical-analysis
Role-of-lexical-analysis
 
Introduction TO Finite Automata
Introduction TO Finite AutomataIntroduction TO Finite Automata
Introduction TO Finite Automata
 
Compilers
CompilersCompilers
Compilers
 

Viewers also liked

Computer system
Computer systemComputer system
Computer system
zamzulaiha
 
Introduction to compiler
Introduction to compilerIntroduction to compiler
Introduction to compiler
Abha Damani
 
Computer architecture kai hwang
Computer architecture   kai hwangComputer architecture   kai hwang
Computer architecture kai hwang
Sumedha
 
Lex tool manual
Lex tool manualLex tool manual
Lex tool manual
Sami Said
 

Viewers also liked (20)

compiler and their types
compiler and their typescompiler and their types
compiler and their types
 
Compilers
CompilersCompilers
Compilers
 
Compiler vs Interpreter-Compiler design ppt.
Compiler vs Interpreter-Compiler design ppt.Compiler vs Interpreter-Compiler design ppt.
Compiler vs Interpreter-Compiler design ppt.
 
Recognition-of-tokens
Recognition-of-tokensRecognition-of-tokens
Recognition-of-tokens
 
Computer system
Computer systemComputer system
Computer system
 
Types and components of computer system
Types and components of computer systemTypes and components of computer system
Types and components of computer system
 
Compiler Design Tutorial
Compiler Design Tutorial Compiler Design Tutorial
Compiler Design Tutorial
 
Compilers Design
Compilers DesignCompilers Design
Compilers Design
 
Advanced Computer Architecture Chapter 123 Problems Solution
Advanced Computer Architecture Chapter 123 Problems SolutionAdvanced Computer Architecture Chapter 123 Problems Solution
Advanced Computer Architecture Chapter 123 Problems Solution
 
Introduction to compiler
Introduction to compilerIntroduction to compiler
Introduction to compiler
 
Yacc (yet another compiler compiler)
Yacc (yet another compiler compiler)Yacc (yet another compiler compiler)
Yacc (yet another compiler compiler)
 
Interpreter
InterpreterInterpreter
Interpreter
 
Language translator
Language translatorLanguage translator
Language translator
 
compiler vs interpreter
compiler vs interpretercompiler vs interpreter
compiler vs interpreter
 
Advanced Comuter Architecture Ch6 Problem Solutions
Advanced Comuter Architecture Ch6 Problem SolutionsAdvanced Comuter Architecture Ch6 Problem Solutions
Advanced Comuter Architecture Ch6 Problem Solutions
 
Computer architecture kai hwang
Computer architecture   kai hwangComputer architecture   kai hwang
Computer architecture kai hwang
 
Lex tool manual
Lex tool manualLex tool manual
Lex tool manual
 
OpenGL Projects on SIMULATION OF WATER RIPPELS
OpenGL Projects on SIMULATION OF WATER RIPPELSOpenGL Projects on SIMULATION OF WATER RIPPELS
OpenGL Projects on SIMULATION OF WATER RIPPELS
 
Lexical analyzer
Lexical analyzerLexical analyzer
Lexical analyzer
 
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
 

Similar to Techniques & applications of Compiler

Compier Design_Unit I_SRM.ppt
Compier Design_Unit I_SRM.pptCompier Design_Unit I_SRM.ppt
Compier Design_Unit I_SRM.ppt
Apoorv Diwan
 

Similar to Techniques & applications of Compiler (20)

lec00-Introduction.pdf
lec00-Introduction.pdflec00-Introduction.pdf
lec00-Introduction.pdf
 
1 compiler outline
1 compiler outline1 compiler outline
1 compiler outline
 
1 cc
1 cc1 cc
1 cc
 
Presentation1
Presentation1Presentation1
Presentation1
 
Presentation1
Presentation1Presentation1
Presentation1
 
Compiler1
Compiler1Compiler1
Compiler1
 
Phases of Compiler.pptx
Phases of Compiler.pptxPhases of Compiler.pptx
Phases of Compiler.pptx
 
Compiler design
Compiler designCompiler design
Compiler design
 
Cd econtent link1
Cd econtent link1Cd econtent link1
Cd econtent link1
 
Compiler an overview
Compiler  an overviewCompiler  an overview
Compiler an overview
 
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
 
Phases of Compiler
Phases of CompilerPhases of Compiler
Phases of Compiler
 
Compier Design_Unit I.ppt
Compier Design_Unit I.pptCompier Design_Unit I.ppt
Compier Design_Unit I.ppt
 
Compier Design_Unit I.ppt
Compier Design_Unit I.pptCompier Design_Unit I.ppt
Compier Design_Unit I.ppt
 
COMPILER CONSTRUCTION KU 1.pptx
COMPILER CONSTRUCTION KU 1.pptxCOMPILER CONSTRUCTION KU 1.pptx
COMPILER CONSTRUCTION KU 1.pptx
 
Compier Design_Unit I_SRM.ppt
Compier Design_Unit I_SRM.pptCompier Design_Unit I_SRM.ppt
Compier Design_Unit I_SRM.ppt
 
Cpcs302 1
Cpcs302  1Cpcs302  1
Cpcs302 1
 
Concept of compiler in details
Concept of compiler in detailsConcept of compiler in details
Concept of compiler in details
 
Chapter 1.pptx
Chapter 1.pptxChapter 1.pptx
Chapter 1.pptx
 
1._Introduction_.pptx
1._Introduction_.pptx1._Introduction_.pptx
1._Introduction_.pptx
 

Recently uploaded

Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
KarakKing
 

Recently uploaded (20)

Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
How to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxHow to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptx
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptx
 
REMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxREMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptx
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 

Techniques & applications of Compiler

  • 1. Introduction to Techniques and Applications of Compiler Design By, R.Preethi M.Sc.,
  • 2. Introduction to Techniques and Applications of Complier Design What is Compiler? A compiler is a program takes a program written in a source language and translates it into an equivalent program in a target language. Major Parts of Compilers There are two major parts of a compiler: Analysis Phase In analysis phase, an intermediate representation is created from the given source program. – Lexical Analyzer, Syntax Analyzer and Semantic Analyzer are the parts of this phase. Synthesis Phase In synthesis phase, the equivalent target program is created from this intermediate representation. – Intermediate Code Generator, Code Generator, and Code Optimizer are the parts of this phase. Phases of A Compiler • Each phase transforms the source program from one representation into another representation. • They communicate with error handlers. • They communicate with the symbol table.
  • 3. Lexical Analyzer • Lexical Analyzer reads the source program character by character and returns the tokens of the source program. • A token describes a pattern of characters having same meaning in the source program. (such as identifiers, operators, keywords, numbers, delimeters and so on) Ex: newval := oldval + 12 => tokens: newval identifier := assignment operator oldval identifier + add operator 12 a number • Puts information about identifiers into the symbol table. • Regular expressions are used to describe tokens (lexical constructs). • A (Deterministic) Finite State Automaton can be used in the implementation of a lexical analyzer. Syntax Analyzer • A Syntax Analyzer creates the syntactic structure (generally a parse tree) of the given program. • A syntax analyzer is also called as a parser. • A parse tree describes a syntactic structure. assgstmt identifier := expression newval expression + expression identifier number oldval 12
  • 4. Parsing Techniques • The parsing techniques are categorized into two groups:  Top-Down Parsing,  Bottom-Up Parsing • Top-Down Parsing:  Construction of the parse tree starts at the root, and proceeds towards the leaves.  Efficient top-down parsers can be easily constructed by hand.  Recursive Predictive Parsing, Non-Recursive Predictive Parsing (LL Parsing). • Bottom-Up Parsing:  Construction of the parse tree starts at the leaves, and proceeds towards the root.  Normally efficient bottom-up parsers are created with the help of some software tools.  Bottom-up parsing is also known as shift-reduce parsing.  Operator-Precedence Parsing – simple, restrictive, easy to implement  LR Parsing – much general form of shift-reduce parsing, LR, SLR, LALR Semantic Analyzer • A semantic analyzer checks the source program for semantic errors and collects the type information for the code generation. • Type-checking is an important part of semantic analyzer. • Normally semantic information cannot be represented by a context-free language used in syntax analyzers. • Context-free grammars used in the syntax analysis are integrated with attributes (semantic rules) – the result is a syntax-directed translation, – Attribute grammars • Ex:
  • 5. newval := oldval + 12 Intermediate Code Generation • A compiler may produce an explicit intermediate codes representing the source program. • These intermediate codes are generally machine (architecture independent). But the level of intermediate codes is close to the level of machine codes. • Ex: newval := oldval * fact + 1 id1 := id2 * id3 + 1 MULT id2,id3,temp1 Intermediates Codes (Quadraples) ADD temp1,#1,temp2 MOV temp2,,id1 Code Optimizer • The code optimizer optimizes the code produced by the intermediate code generator in the terms of time and space. • Ex: MULT id2, id3,temp1 ADD temp1,#1,id1 Code Generator • Produces the target language in a specific architecture. • The target program is normally is a relocatable object file containing the machine codes. • Ex: MOVEid2,R1
  • 6. MULT id3,R1 ADD #1,R1 MOVER1,id1 Applications In addition to the development of a compiler, the techniques used in compiler design can be applicable to many problems in computer science.  Techniques used in a lexical analyzer can be used in text editors, information retrieval system, and pattern recognition programs.  Techniques used in a parser can be used in a query processing system such as SQL.  Many software having a complex front-end may need techniques used in compiler design. Most of the techniques used in compiler design can be used in Natural Language Processing (NLP) systems Conclusion These are the basic techniques of a compiler design and applications of compiler design in computer science apart from the purpose of a compiler.