SlideShare a Scribd company logo
1 of 17
Bottom-UP Parsing
Subtitle
Content Layout
• Bottom UP Parsing
• SLR(1)
• LR(1)
• LALR(1)
• Shift-Reduce Parsing
Bottom-Up Parsing
• Bottom-up parsing starts with the input symbols and tries to construct
the parse tree up to the start symbol.
• Bottom-up parsing starts from the leaf nodes of a tree and works in
upward direction till it reaches the root node.
• It is convenient to describe parsing as the process of building parse
trees.
Bottom-Up Parsing
• There are three widely used algorithms available for constructing an
LR parser:
SLR(1) – Simple LR Parser:
o Works on smallest class of grammar
o Few number of states, hence very small table
o Simple and fast construction
• LR(1) – LR Parser:
o Works on complete set of LR(1) Grammar
o Generates large table and large number of states
o Slow construction
• LALR(1) – Look-Ahead LR Parser:
o Works on intermediate size of grammar
o Number of states are same as in SLR(1)
Bottom-Up Parsing (Cont..)
Shift-Reduce Parsing
• Shift-reduce parsing uses two unique steps for bottom-up parsing.
• These steps are known as shift-step and reduce-step.
• Shift step:
• The shift step refers to the advancement of the input pointer to the
next input symbol, which is called the shifted symbol.
• This symbol is pushed onto the stack. The shifted symbol is treated as
a single node of the parse tree.
Shift-Reduce Parsing
• Reduce step :
• When the parser finds a complete grammar rule (RHS) and replaces it
to (LHS), it is known as reduce-step.
• This occurs when the top of the stack contains a handle.
• To reduce, a POP function is performed on the stack which pops off the
handle and replaces it with LHS non-terminal symbol.
IMPLEMENTATION OF SHIFT-REDUCE
PARSING
• A convenient way to implement a shift-reduce parser is to use a stack to hold
grammar symbols and an input buffer to hold the string w to be parsed. The
symbol $ is used to mark the bottom of the stack and also the right-end of the
input.
• Notationally, the top of the stack is identified through a separator symbol |,
and the input string to be parsed appears on the right side of |. The stack
content appears on the left of |.
• For example, an intermediate stage of parsing can be shown as follows:
$id1 | + id2 * id3$ …. (1)
• Here “$id1” is in the stack, while the input yet to be seen is “+ id2 * id3$*
IMPLEMENTATION OF SHIFT-REDUCE
PARSING
• Shift operation:
• The next input symbol is shifted onto the top of the stack.
• After shifting + into the stack, the above state captured in (1) would
change into:
$id1 + | id2 * id3$ …….(2)
IMPLEMENTATION OF SHIFT-REDUCE
PARSING
• Reduce operation:
• Replaces a set of grammar symbols on the top of the stack with the
LHS of a production rule.
• After reducing id1 using E → id, the state (1) would change into:
$E | + id2 * id3$... (3)
Reductions
• We can think of bottom-up parsing as the process of "reducing" a string
w to the start symbol of the grammar.
• At each reduction step, a specific substring matching the body of a
production is replaced by the non-terminal at the head of that
production.
• The key decisions during bottom-up parsing are about when to reduce
and about what production to apply, as the parse proceeds.
Conflicts During Shift-Reduce
Parsing
• There are context-free grammars for which shift-reduce parsing cannot
be used.
• Every shift-reduce parser for such a grammar can reach a
configuration in which the parser, knowing the entire stack contents
and the next input symbol, cannot decide whether to shift or to reduce
(a shift/reduce conflict) Or cannot decide which of several reductions to
make (a reduce/reduce conflict).
Conflicts During Shift-Reduce
Parsing (Cont..)
• Note that shift-reduce parsing can be adapted to parse certain
ambiguous grammars, such as the if-then-else grammar.
• If we resolve the shift/reduce conflict on, the parser will behave as we
expect.
LR parser
• A general form of shift-reduce parsing is LR (scanning from Left to right and
using Right-most derivation in reverse) parsing, which is used in a number of
automatic parser generators .
• The LR parser is a non-recursive, shift-reduce, bottom-up parser.
• It uses a wide class of context-free grammar which makes it the most efficient
syntax analysis technique.
• LR parsers are also known as LR(k) parsers, where L stands for left-to-right
scanning of the input stream; R stands for the construction of right-most
derivation in reverse, and k denotes the number of lookahead symbols to
make decisions.
Conclusion
• What is Bottom -UP parsing
• How to shift reduce steps implement
• What are Conflicts exist during Shift-Reduce Parsing

More Related Content

Similar to Lecture 12 Bottom-UP Parsing.pptx

Similar to Lecture 12 Bottom-UP Parsing.pptx (20)

04 Syntax Analysis - RDP.pptx
04 Syntax Analysis - RDP.pptx04 Syntax Analysis - RDP.pptx
04 Syntax Analysis - RDP.pptx
 
Bottom up parser
Bottom up parserBottom up parser
Bottom up parser
 
LR PARSE.pptx
LR PARSE.pptxLR PARSE.pptx
LR PARSE.pptx
 
Unitiv 111206005201-phpapp01
Unitiv 111206005201-phpapp01Unitiv 111206005201-phpapp01
Unitiv 111206005201-phpapp01
 
Implementation of lexical analyser
Implementation of lexical analyserImplementation of lexical analyser
Implementation of lexical analyser
 
PDA and Turing Machine (1).ppt
PDA and Turing Machine (1).pptPDA and Turing Machine (1).ppt
PDA and Turing Machine (1).ppt
 
Non- Recursive Predictive Parsing.pptx
Non- Recursive Predictive Parsing.pptxNon- Recursive Predictive Parsing.pptx
Non- Recursive Predictive Parsing.pptx
 
Compilers section 4.7
Compilers section 4.7Compilers section 4.7
Compilers section 4.7
 
RECURSIVE DESCENT PARSING
RECURSIVE DESCENT PARSINGRECURSIVE DESCENT PARSING
RECURSIVE DESCENT PARSING
 
COMPILER DESIGN- Syntax Analysis
COMPILER DESIGN- Syntax AnalysisCOMPILER DESIGN- Syntax Analysis
COMPILER DESIGN- Syntax Analysis
 
Programming_Language_Syntax.ppt
Programming_Language_Syntax.pptProgramming_Language_Syntax.ppt
Programming_Language_Syntax.ppt
 
Top Down Parsing, Predictive Parsing
Top Down Parsing, Predictive ParsingTop Down Parsing, Predictive Parsing
Top Down Parsing, Predictive Parsing
 
Lecture 15 16
Lecture 15 16Lecture 15 16
Lecture 15 16
 
Compiler unit 2&3
Compiler unit 2&3Compiler unit 2&3
Compiler unit 2&3
 
Lisp
LispLisp
Lisp
 
Lecture9 syntax analysis_5
Lecture9 syntax analysis_5Lecture9 syntax analysis_5
Lecture9 syntax analysis_5
 
Predictive parser
Predictive parserPredictive parser
Predictive parser
 
BOTTOM UP PARSING GROUP 3.pptx
BOTTOM UP PARSING GROUP 3.pptxBOTTOM UP PARSING GROUP 3.pptx
BOTTOM UP PARSING GROUP 3.pptx
 
Regular Expression to Finite Automata
Regular Expression to Finite AutomataRegular Expression to Finite Automata
Regular Expression to Finite Automata
 
Pseudo code
Pseudo codePseudo code
Pseudo code
 

Recently uploaded

Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxHistory Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxsocialsciencegdgrohi
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxthorishapillay1
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTiammrhaywood
 
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
 
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
 
Biting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfBiting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfadityarao40181
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxiammrhaywood
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Celine George
 
CELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxCELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxJiesonDelaCerna
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
Types of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxTypes of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxEyham Joco
 
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
 
Meghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media ComponentMeghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media ComponentInMediaRes1
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
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
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
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
 
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
 

Recently uploaded (20)

Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxHistory Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptx
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
 
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
 
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
 
Biting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfBiting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdf
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17
 
CELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxCELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptx
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
Types of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxTypes of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptx
 
ESSENTIAL of (CS/IT/IS) class 06 (database)
ESSENTIAL of (CS/IT/IS) class 06 (database)ESSENTIAL of (CS/IT/IS) class 06 (database)
ESSENTIAL of (CS/IT/IS) class 06 (database)
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdf
 
Meghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media ComponentMeghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media Component
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
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
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
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 ...
 
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
 

Lecture 12 Bottom-UP Parsing.pptx

  • 2. Content Layout • Bottom UP Parsing • SLR(1) • LR(1) • LALR(1) • Shift-Reduce Parsing
  • 3. Bottom-Up Parsing • Bottom-up parsing starts with the input symbols and tries to construct the parse tree up to the start symbol. • Bottom-up parsing starts from the leaf nodes of a tree and works in upward direction till it reaches the root node. • It is convenient to describe parsing as the process of building parse trees.
  • 4. Bottom-Up Parsing • There are three widely used algorithms available for constructing an LR parser: SLR(1) – Simple LR Parser: o Works on smallest class of grammar o Few number of states, hence very small table o Simple and fast construction
  • 5. • LR(1) – LR Parser: o Works on complete set of LR(1) Grammar o Generates large table and large number of states o Slow construction • LALR(1) – Look-Ahead LR Parser: o Works on intermediate size of grammar o Number of states are same as in SLR(1)
  • 6.
  • 8. Shift-Reduce Parsing • Shift-reduce parsing uses two unique steps for bottom-up parsing. • These steps are known as shift-step and reduce-step. • Shift step: • The shift step refers to the advancement of the input pointer to the next input symbol, which is called the shifted symbol. • This symbol is pushed onto the stack. The shifted symbol is treated as a single node of the parse tree.
  • 9. Shift-Reduce Parsing • Reduce step : • When the parser finds a complete grammar rule (RHS) and replaces it to (LHS), it is known as reduce-step. • This occurs when the top of the stack contains a handle. • To reduce, a POP function is performed on the stack which pops off the handle and replaces it with LHS non-terminal symbol.
  • 10. IMPLEMENTATION OF SHIFT-REDUCE PARSING • A convenient way to implement a shift-reduce parser is to use a stack to hold grammar symbols and an input buffer to hold the string w to be parsed. The symbol $ is used to mark the bottom of the stack and also the right-end of the input. • Notationally, the top of the stack is identified through a separator symbol |, and the input string to be parsed appears on the right side of |. The stack content appears on the left of |. • For example, an intermediate stage of parsing can be shown as follows: $id1 | + id2 * id3$ …. (1) • Here “$id1” is in the stack, while the input yet to be seen is “+ id2 * id3$*
  • 11. IMPLEMENTATION OF SHIFT-REDUCE PARSING • Shift operation: • The next input symbol is shifted onto the top of the stack. • After shifting + into the stack, the above state captured in (1) would change into: $id1 + | id2 * id3$ …….(2)
  • 12. IMPLEMENTATION OF SHIFT-REDUCE PARSING • Reduce operation: • Replaces a set of grammar symbols on the top of the stack with the LHS of a production rule. • After reducing id1 using E → id, the state (1) would change into: $E | + id2 * id3$... (3)
  • 13. Reductions • We can think of bottom-up parsing as the process of "reducing" a string w to the start symbol of the grammar. • At each reduction step, a specific substring matching the body of a production is replaced by the non-terminal at the head of that production. • The key decisions during bottom-up parsing are about when to reduce and about what production to apply, as the parse proceeds.
  • 14. Conflicts During Shift-Reduce Parsing • There are context-free grammars for which shift-reduce parsing cannot be used. • Every shift-reduce parser for such a grammar can reach a configuration in which the parser, knowing the entire stack contents and the next input symbol, cannot decide whether to shift or to reduce (a shift/reduce conflict) Or cannot decide which of several reductions to make (a reduce/reduce conflict).
  • 15. Conflicts During Shift-Reduce Parsing (Cont..) • Note that shift-reduce parsing can be adapted to parse certain ambiguous grammars, such as the if-then-else grammar. • If we resolve the shift/reduce conflict on, the parser will behave as we expect.
  • 16. LR parser • A general form of shift-reduce parsing is LR (scanning from Left to right and using Right-most derivation in reverse) parsing, which is used in a number of automatic parser generators . • The LR parser is a non-recursive, shift-reduce, bottom-up parser. • It uses a wide class of context-free grammar which makes it the most efficient syntax analysis technique. • LR parsers are also known as LR(k) parsers, where L stands for left-to-right scanning of the input stream; R stands for the construction of right-most derivation in reverse, and k denotes the number of lookahead symbols to make decisions.
  • 17. Conclusion • What is Bottom -UP parsing • How to shift reduce steps implement • What are Conflicts exist during Shift-Reduce Parsing