In this article, we are going to cover working of the bottom-up parser and will see how we can take input and parse it and also cover some basics of bottom-up parser.
Pre-requisite – Parsing
Bottom-up parser :
- It will start from string and proceed to start.
- In Bottom-up parser, Identifying the correct handle (substring) is always difficult.
- It will follow rightmost derivation in reverse order.
In bottom-up parser, no variable that’s why not have any derivation from the bottom but in reverse order it is looking like top-down, when you have rightmost derivation.
Working of Bottom-up parser :
Let’s consider an example where grammar is given and you need to construct a parse tree by using bottom-up parser technique.
S -> aABe A -> Abc | b B -> d
Now, let’s consider the input to read and to construct a parse tree with bottom-up approach.
Now, you will see that how bottom-up approach works. Here, you will see how you can generate a input string from the grammar for bottom-up approach.
- First, you can start with A -> b.
- Now, expand A -> Abc.
- After that Exapnd B-> d.
- In the last, just expand the S -> aABe
- Final string, you will get abbcde.
Given below is the Diagram explanation for constructing bottom-up parse tree. You can see clearly in the diagram how you can generate the input string using grammar with bottom-up approach.
From the above explanation and diagram, you can clearly see and can say it follows reverse of the rightmost derivation.
Attention reader! Don’t stop learning now. Get hold of all the important CS Theory concepts for SDE interviews with the CS Theory Course at a student-friendly price and become industry ready.
- Difference between Recursive Predictive Descent Parser and Non-Recursive Predictive Descent Parser
- Working of top down parser
- Shift Reduce Parser in Compiler
- Recursive Descent Parser
- Difference between LL and LR parser
- Parsing ambiguos grammars using LR parser
- Operator grammar and precedence parser in TOC
- Working of ISO-OSI Model
- Working of Compiler Phases with Example
- Working of Lexical Analyzer in compiler
- Bottom Up or Shift Reduce Parsers | Set 2
- Difference between Top down parsing and Bottom up parsing
- Viable Prefix in Bottom-up Parsing
- Layered Operating System
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.