SlideShare a Scribd company logo
1 of 10
TERM PAPER ON
PARSING
COURSE CODE: CAP632
SECTION: D1809
COURSES NAME:
FORMAL LANGUAGES AND AUTOMATION THEORY
SUBMITED BY: SUBMITED TO:
11607193 Shrikant Sharma Miss Pallvi
What is Parser?
 A Parser is a compiler or interpreter component that breaks the data into
smaller elements for easy translation into another language.
 It takes input form of sequence of tokens or program instructions and build
the data structure in the form of parse tree.
What is the Role of Parser?
source token parse intermediate
Programmed getnext token tree representation
 In the compiler model, the parser obtains a string of token from the lexical
analyser, and verifies the string can be generated by the grammar for the
sourcelanguage.
 The parser returns any syntax error for the source language.
 It collects sufficient number of tokens and builds a parse tree.
LEXICAL
ANALYSER
REST OF FRONT
END
SYMBOL TABLE
PARSER
What is Parsing?
o Parsing is used to derived a string using the production rules of grammar.
o It is used to check the acceptability of string.
Example of Parsing
Problem: Consider the grammar
S=S+S | S*S | a | b
Constructthe derivation tree or parse tree for the string (w = a + b * b)
Solution:
S
S + S
a S * S
b b
Types of Parsing
Types of Parsing
Top-Down Parsing Bottom-Up Parsing
Backtracking
Predictive Parsing
Left to Right (LR)
Parsing
Shift Reduce Parsing
Simple Left to Right
(SLR)
Left to Right (LR)
Look-Ahead Left to Right
(LALR)
Types of Parsing
There are two types of parsing:
(i) Top-Down Parsing
(ii) Bottom-Up Parsing
Top-DownParsing
 Top-Down Parsing starts from the top with the start symboland derives a
string using parse tree.
 It may Backtracking.
Designof Top-DownParsing
For top-down parsing, a PDA has the following four types of transitions −
 Pop the non-terminal on the left-hand side of the production at the top of the
stack and push its right-hand side string.
 If the top symbol of the stack matches with the input symbol being read,
pop it.
 Push the start symbol ‘S’ into the stack.
 If the input string is fully read and the stack is empty, go to the final state ‘F
Example of Top-DownParsing
Example 1: Let us consider the following grammar.
S -> cAd
A -> ab | a
Let input string w = cad
S S
c A d c A d
a b a
(a) (b)
Let written in programming language:
Procedure S
ProcedureS (),
Begin
If input symbol= ‘c’ then
Begin
ADVANCE ();
If A () then
If input symbol= ‘d’ then
Begin ADVANCE (),
Return true
End
End
Return false
End
Procedure A ()
ProcedureA (),
Begin
isave=input-pointer;
If input symbol= ‘a’ then
Begin
ADVANCE (),
If input symbol= ‘b’ then
Begin ADVANCE (),
Return true
End
End
** if return true will not be terminated.
input-pointer=isave;
If input symbol= ‘a’ then
Begin
ADVANCE (),
Return true
End
Else
Return false
End
Example 2: let consider these equation
E -> E+E
E -> E*E
E -> a
E -> b
Input strings: (a*b) + (a*b)
** This parsing technique uses Left Most Derivation.
Solution:
E -> E+E
E -> E*E + E
E -> a*E+E
E -> a*b + E
E -> a*b + E+E
E -> a*b + E*E
E -> a*b + a* E
E -> a*b + a*b
Problem of Top-DownParsing
(i) Backtracking
 Backtracking is a technique in which for expansion of non-terminal
symbol we chooseone alternative and if some mismatch occurs then
we try to other alternative if any.
(ii) Left Recursion
 Left Recursion is removed if the parser performs top-downparsing.
E
E + E
E * E E * E
a b a b
(iii) Left Factoring
 Left Factoring is removing the common left factor that appears in two
productions of the same non-terminal. It is done to avoid the
backtracking by the parser.
Bottom-Up Parsing
Bottom-Up Parsing starts from the bottom with the string and comes to the
start symbolusing parse tree.
It uses stack to store both state and sentential forms.
Designof a Bottom-Up Parser
For bottom-up parsing, a PDA has the following four types of transitions −
 Push the current input symbol into the stack.
 Replace the right-hand side of a production at the top of the stack with its
left-hand side.
 If the top of the stack element matches with the current input symbol, pop it.
 If the input string is fully read and only if the start symbol ‘S’ remains in the
stack, pop it and go to the final state ‘F’.
Example of Bottom-Up Parsing
let consider these equation
E -> E+E
E -> E*E
E -> a
E -> b
Input strings: (a*b) + (a*b)
** This parsing technique uses Right MostDerivation.
Solution:
E -> E+E
E -> E + E*E
E -> E + E * b
E -> E + a * b
E -> E*E + a*b
E -> E * b + a*b
E -> a*b + a*b
References
https://www.slideshare.net/khush_boo31/parsing-67077365
https://www.youtube.com/watch?v=WYb-Iblk7J0
https://www.youtube.com/watch?v=42nqWoHacxg
https://www.youtube.com/watch?v=7LwxK2B_H3k
E
E E
E E E E
a * b + a * b

More Related Content

What's hot

Syntax directed translation
Syntax directed translationSyntax directed translation
Syntax directed translationAkshaya Arunan
 
Symbol table in compiler Design
Symbol table in compiler DesignSymbol table in compiler Design
Symbol table in compiler DesignKuppusamy P
 
Lecture 04 syntax analysis
Lecture 04 syntax analysisLecture 04 syntax analysis
Lecture 04 syntax analysisIffat Anjum
 
Lexical Analysis - Compiler Design
Lexical Analysis - Compiler DesignLexical Analysis - Compiler Design
Lexical Analysis - Compiler DesignAkhil Kaushik
 
Type checking in compiler design
Type checking in compiler designType checking in compiler design
Type checking in compiler designSudip Singh
 
Ll(1) Parser in Compilers
Ll(1) Parser in CompilersLl(1) Parser in Compilers
Ll(1) Parser in CompilersMahbubur Rahman
 
Syntax analyzer
Syntax analyzerSyntax analyzer
Syntax analyzerahmed51236
 
Parsing in Compiler Design
Parsing in Compiler DesignParsing in Compiler Design
Parsing in Compiler DesignAkhil Kaushik
 
Code generation in Compiler Design
Code generation in Compiler DesignCode generation in Compiler Design
Code generation in Compiler DesignKuppusamy P
 
Pattern matching
Pattern matchingPattern matching
Pattern matchingshravs_188
 
RECURSIVE DESCENT PARSING
RECURSIVE DESCENT PARSINGRECURSIVE DESCENT PARSING
RECURSIVE DESCENT PARSINGJothi Lakshmi
 

What's hot (20)

Parse Tree
Parse TreeParse Tree
Parse Tree
 
Syntax directed translation
Syntax directed translationSyntax directed translation
Syntax directed translation
 
Symbol table in compiler Design
Symbol table in compiler DesignSymbol table in compiler Design
Symbol table in compiler Design
 
First and follow set
First and follow setFirst and follow set
First and follow set
 
Lecture 04 syntax analysis
Lecture 04 syntax analysisLecture 04 syntax analysis
Lecture 04 syntax analysis
 
Chapter 5 Syntax Directed Translation
Chapter 5   Syntax Directed TranslationChapter 5   Syntax Directed Translation
Chapter 5 Syntax Directed Translation
 
Lexical Analysis - Compiler Design
Lexical Analysis - Compiler DesignLexical Analysis - Compiler Design
Lexical Analysis - Compiler Design
 
Type checking in compiler design
Type checking in compiler designType checking in compiler design
Type checking in compiler design
 
Ll(1) Parser in Compilers
Ll(1) Parser in CompilersLl(1) Parser in Compilers
Ll(1) Parser in Compilers
 
Syntax analyzer
Syntax analyzerSyntax analyzer
Syntax analyzer
 
Specification-of-tokens
Specification-of-tokensSpecification-of-tokens
Specification-of-tokens
 
Recognition-of-tokens
Recognition-of-tokensRecognition-of-tokens
Recognition-of-tokens
 
Parsing in Compiler Design
Parsing in Compiler DesignParsing in Compiler Design
Parsing in Compiler Design
 
Top down parsing
Top down parsingTop down parsing
Top down parsing
 
Code generation in Compiler Design
Code generation in Compiler DesignCode generation in Compiler Design
Code generation in Compiler Design
 
Pattern matching
Pattern matchingPattern matching
Pattern matching
 
RECURSIVE DESCENT PARSING
RECURSIVE DESCENT PARSINGRECURSIVE DESCENT PARSING
RECURSIVE DESCENT PARSING
 
Finite Automata
Finite AutomataFinite Automata
Finite Automata
 
Top down parsing
Top down parsingTop down parsing
Top down parsing
 
Parsing LL(1), SLR, LR(1)
Parsing LL(1), SLR, LR(1)Parsing LL(1), SLR, LR(1)
Parsing LL(1), SLR, LR(1)
 

Similar to Parsing

Similar to Parsing (20)

Theory of automata and formal language lab manual
Theory of automata and formal language lab manualTheory of automata and formal language lab manual
Theory of automata and formal language lab manual
 
Chapter-3 compiler.pptx course materials
Chapter-3 compiler.pptx course materialsChapter-3 compiler.pptx course materials
Chapter-3 compiler.pptx course materials
 
Top Down Parsing, Predictive Parsing
Top Down Parsing, Predictive ParsingTop Down Parsing, Predictive Parsing
Top Down Parsing, Predictive Parsing
 
Assignment10
Assignment10Assignment10
Assignment10
 
Syntactic analysis in NLP
Syntactic analysis in NLPSyntactic analysis in NLP
Syntactic analysis in NLP
 
Module 11
Module 11Module 11
Module 11
 
Cd2 [autosaved]
Cd2 [autosaved]Cd2 [autosaved]
Cd2 [autosaved]
 
Top down parsing
Top down parsingTop down parsing
Top down parsing
 
07 top-down-parsing
07 top-down-parsing07 top-down-parsing
07 top-down-parsing
 
Ch3_Syntax Analysis.pptx
Ch3_Syntax Analysis.pptxCh3_Syntax Analysis.pptx
Ch3_Syntax Analysis.pptx
 
Regular Expressions To Finite Automata
Regular Expressions To Finite AutomataRegular Expressions To Finite Automata
Regular Expressions To Finite Automata
 
Chapter 3 -Syntax Analyzer.ppt
Chapter 3 -Syntax Analyzer.pptChapter 3 -Syntax Analyzer.ppt
Chapter 3 -Syntax Analyzer.ppt
 
Ch06
Ch06Ch06
Ch06
 
3. Syntax Analyzer.pptx
3. Syntax Analyzer.pptx3. Syntax Analyzer.pptx
3. Syntax Analyzer.pptx
 
STRINGS_IN_PYTHON 9-12 (1).pptx
STRINGS_IN_PYTHON 9-12 (1).pptxSTRINGS_IN_PYTHON 9-12 (1).pptx
STRINGS_IN_PYTHON 9-12 (1).pptx
 
Ch09
Ch09Ch09
Ch09
 
Nonrecursive predictive parsing
Nonrecursive predictive parsingNonrecursive predictive parsing
Nonrecursive predictive parsing
 
01 stack 20160908_jintaek_seo
01 stack 20160908_jintaek_seo01 stack 20160908_jintaek_seo
01 stack 20160908_jintaek_seo
 
COMPILER DESIGN- Syntax Analysis
COMPILER DESIGN- Syntax AnalysisCOMPILER DESIGN- Syntax Analysis
COMPILER DESIGN- Syntax Analysis
 
8-Practice problems on operator precedence parser-24-05-2023.docx
8-Practice problems on operator precedence parser-24-05-2023.docx8-Practice problems on operator precedence parser-24-05-2023.docx
8-Practice problems on operator precedence parser-24-05-2023.docx
 

More from ShrikantSharma86

More from ShrikantSharma86 (18)

Encryption techniques
Encryption techniques Encryption techniques
Encryption techniques
 
Various aspects of organizational behavior
Various aspects of organizational behaviorVarious aspects of organizational behavior
Various aspects of organizational behavior
 
Artificial intelligence
Artificial intelligenceArtificial intelligence
Artificial intelligence
 
Industrial pollution
Industrial  pollutionIndustrial  pollution
Industrial pollution
 
Ethics in Human Resource Management (HRM) of an Organisation
Ethics in Human Resource Management (HRM) of an OrganisationEthics in Human Resource Management (HRM) of an Organisation
Ethics in Human Resource Management (HRM) of an Organisation
 
Library Management System (LMS)
Library Management System (LMS)Library Management System (LMS)
Library Management System (LMS)
 
RAM (RANDOM ACCESS MEMORY)
RAM (RANDOM ACCESS MEMORY)RAM (RANDOM ACCESS MEMORY)
RAM (RANDOM ACCESS MEMORY)
 
Online Education
Online EducationOnline Education
Online Education
 
Electronic Ink Technology
Electronic Ink TechnologyElectronic Ink Technology
Electronic Ink Technology
 
Audio System Measurements
Audio System MeasurementsAudio System Measurements
Audio System Measurements
 
Personality
PersonalityPersonality
Personality
 
Perception
PerceptionPerception
Perception
 
Organizational culture
Organizational cultureOrganizational culture
Organizational culture
 
Motivation
MotivationMotivation
Motivation
 
Leadership
LeadershipLeadership
Leadership
 
14 principles of management of Henry fayol
14 principles of management of Henry fayol14 principles of management of Henry fayol
14 principles of management of Henry fayol
 
Report on employee satisfaction
Report on employee satisfactionReport on employee satisfaction
Report on employee satisfaction
 
Golden ratio and Fibonacci series
Golden ratio and Fibonacci seriesGolden ratio and Fibonacci series
Golden ratio and Fibonacci series
 

Recently uploaded

How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17Celine George
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatYousafMalik24
 
Painted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaPainted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaVirag Sontakke
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Celine George
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfMahmoud M. Sallam
 
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...M56BOOKSTORE PRODUCT/SERVICE
 
Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementmkooblal
 
Final demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxFinal demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxAvyJaneVismanos
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxRaymartEstabillo3
 
Biting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfBiting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfadityarao40181
 
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfUjwalaBharambe
 
internship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerinternship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerunnathinaik
 

Recently uploaded (20)

How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice great
 
Painted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaPainted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of India
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdf
 
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
 
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of management
 
Final demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxFinal demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptx
 
OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
 
Biting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfBiting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdf
 
9953330565 Low Rate Call Girls In Rohini Delhi NCR
9953330565 Low Rate Call Girls In Rohini  Delhi NCR9953330565 Low Rate Call Girls In Rohini  Delhi NCR
9953330565 Low Rate Call Girls In Rohini Delhi NCR
 
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
 
internship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerinternship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developer
 

Parsing

  • 1. TERM PAPER ON PARSING COURSE CODE: CAP632 SECTION: D1809 COURSES NAME: FORMAL LANGUAGES AND AUTOMATION THEORY SUBMITED BY: SUBMITED TO: 11607193 Shrikant Sharma Miss Pallvi
  • 2. What is Parser?  A Parser is a compiler or interpreter component that breaks the data into smaller elements for easy translation into another language.  It takes input form of sequence of tokens or program instructions and build the data structure in the form of parse tree. What is the Role of Parser? source token parse intermediate Programmed getnext token tree representation  In the compiler model, the parser obtains a string of token from the lexical analyser, and verifies the string can be generated by the grammar for the sourcelanguage.  The parser returns any syntax error for the source language.  It collects sufficient number of tokens and builds a parse tree. LEXICAL ANALYSER REST OF FRONT END SYMBOL TABLE PARSER
  • 3. What is Parsing? o Parsing is used to derived a string using the production rules of grammar. o It is used to check the acceptability of string. Example of Parsing Problem: Consider the grammar S=S+S | S*S | a | b Constructthe derivation tree or parse tree for the string (w = a + b * b) Solution: S S + S a S * S b b
  • 4. Types of Parsing Types of Parsing Top-Down Parsing Bottom-Up Parsing Backtracking Predictive Parsing Left to Right (LR) Parsing Shift Reduce Parsing Simple Left to Right (SLR) Left to Right (LR) Look-Ahead Left to Right (LALR)
  • 5. Types of Parsing There are two types of parsing: (i) Top-Down Parsing (ii) Bottom-Up Parsing Top-DownParsing  Top-Down Parsing starts from the top with the start symboland derives a string using parse tree.  It may Backtracking. Designof Top-DownParsing For top-down parsing, a PDA has the following four types of transitions −  Pop the non-terminal on the left-hand side of the production at the top of the stack and push its right-hand side string.  If the top symbol of the stack matches with the input symbol being read, pop it.  Push the start symbol ‘S’ into the stack.  If the input string is fully read and the stack is empty, go to the final state ‘F Example of Top-DownParsing Example 1: Let us consider the following grammar. S -> cAd A -> ab | a Let input string w = cad
  • 6. S S c A d c A d a b a (a) (b) Let written in programming language: Procedure S ProcedureS (), Begin If input symbol= ‘c’ then Begin ADVANCE (); If A () then If input symbol= ‘d’ then Begin ADVANCE (), Return true End End Return false End
  • 7. Procedure A () ProcedureA (), Begin isave=input-pointer; If input symbol= ‘a’ then Begin ADVANCE (), If input symbol= ‘b’ then Begin ADVANCE (), Return true End End ** if return true will not be terminated. input-pointer=isave; If input symbol= ‘a’ then Begin ADVANCE (), Return true End Else Return false End
  • 8. Example 2: let consider these equation E -> E+E E -> E*E E -> a E -> b Input strings: (a*b) + (a*b) ** This parsing technique uses Left Most Derivation. Solution: E -> E+E E -> E*E + E E -> a*E+E E -> a*b + E E -> a*b + E+E E -> a*b + E*E E -> a*b + a* E E -> a*b + a*b Problem of Top-DownParsing (i) Backtracking  Backtracking is a technique in which for expansion of non-terminal symbol we chooseone alternative and if some mismatch occurs then we try to other alternative if any. (ii) Left Recursion  Left Recursion is removed if the parser performs top-downparsing. E E + E E * E E * E a b a b
  • 9. (iii) Left Factoring  Left Factoring is removing the common left factor that appears in two productions of the same non-terminal. It is done to avoid the backtracking by the parser. Bottom-Up Parsing Bottom-Up Parsing starts from the bottom with the string and comes to the start symbolusing parse tree. It uses stack to store both state and sentential forms. Designof a Bottom-Up Parser For bottom-up parsing, a PDA has the following four types of transitions −  Push the current input symbol into the stack.  Replace the right-hand side of a production at the top of the stack with its left-hand side.  If the top of the stack element matches with the current input symbol, pop it.  If the input string is fully read and only if the start symbol ‘S’ remains in the stack, pop it and go to the final state ‘F’. Example of Bottom-Up Parsing let consider these equation E -> E+E E -> E*E E -> a E -> b
  • 10. Input strings: (a*b) + (a*b) ** This parsing technique uses Right MostDerivation. Solution: E -> E+E E -> E + E*E E -> E + E * b E -> E + a * b E -> E*E + a*b E -> E * b + a*b E -> a*b + a*b References https://www.slideshare.net/khush_boo31/parsing-67077365 https://www.youtube.com/watch?v=WYb-Iblk7J0 https://www.youtube.com/watch?v=42nqWoHacxg https://www.youtube.com/watch?v=7LwxK2B_H3k E E E E E E E a * b + a * b