The Wayback Machine - https://web.archive.org/web/20240818211306/https://www.geeksforgeeks.org/working-of-bottom-up-parser/
Open In App

Working of Bottom up parser

Last Updated : 12 Oct, 2021
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

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.

Note : 
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. 

Example – 
 

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. 

Input – 
 

abbcde$

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 Expand 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.
 



Similar Reads

Difference between Recursive Predictive Descent Parser and Non-Recursive Predictive Descent Parser
Prerequisite - Recursive Descent Parser 1. Recursive Predictive Descent Parser : Recursive Descent Parser is a top-down method of syntax analysis in which a set of recursive procedures is used to process input. One procedure is associated with each non-terminal of a grammar. Here we consider a simple form of recursive descent parsing called Predict
4 min read
Working of top down parser
In this article, we are going to cover working of top down parser and will see how we can take input and parse it and also cover some basics of top down. Pre-requisite - Parsing Top Down Parser : In top down technique parse tree constructs from top and input will read from left to right. In top down, In top down parser, It will start symbol from pr
2 min read
Shift Reduce Parser in Compiler
Prerequisite – Parsing | Set 2 (Bottom Up or Shift Reduce Parsers) Shift Reduce parser attempts for the construction of parse in a similar manner as done in bottom-up parsing i.e. the parse tree is constructed from leaves(bottom) to the root(up). A more general form of the shift-reduce parser is the LR parser. This parser requires some data structu
8 min read
LR Parser
In this article, we will discuss LR parser, and it's overview and then will discuss the algorithm. Also, we will discuss the parsing table and LR parser working diagram. Let's discuss it one by one. LR parser :LR parser is a bottom-up parser for context-free grammar that is very generally used by computer programming language compiler and other ass
3 min read
Recursive Descent Parser
Prerequisite - Construction of LL(1) Parsing Table, Classification of top down parsers Parsing is the process to determine whether the start symbol can derive the program or not. If the Parsing is successful then the program is a valid program otherwise the program is invalid. There are generally two types of Parsers: Top-Down Parsers: In this Pars
4 min read
Difference between LL and LR parser
LL Parser includes both the recursive descent parser and non-recursive descent parser. Its one type uses backtracking while another one uses parsing table. Theses are top down parser. Example: Given grammar is S -> Ac A -> ab where S is start symbol, A is non-terminal and a, b, c are terminals. Input string: abc Parse tree generated by LL par
2 min read
Parsing ambiguous grammars using LR parser
LR parser can be used to parse ambiguous grammars. LR parser resolves the conflicts (shift/reduce or reduce/reduce) in parsing table of ambiguous grammars based on certain rules (precedence and/or associativity of operators) of the grammar. Example: Lets take the following ambiguous grammar: E -> E+E E -> E*E E -> id Lets assume, the prece
3 min read
Role of Operator Precedence Parser
In this, we will cover the overview of Operator Precedence Parser and mainly focus on the role of Operator Precedence Parser. And will also cover the algorithm for the construction of the Precedence function and finally will discuss error recovery in operator precedence parsing. Let's discuss it one by one. Introduction :Operator Precedence Parser
4 min read
CLR Parser (with Examples)
LR parsers :It is an efficient bottom-up syntax analysis technique that can be used to parse large classes of context-free grammar is called LR(k) parsing. L stands for the left to right scanningR stands for rightmost derivation in reversek stands for no. of input symbols of lookahead Advantages of LR parsing : It recognizes virtually all programmi
7 min read
LALR Parser (with Examples)
LALR Parser :LALR Parser is lookahead LR parser. It is the most powerful parser which can handle large classes of grammar. The size of CLR parsing table is quite large as compared to other parsing table. LALR reduces the size of this table.LALR works similar to CLR. The only difference is , it combines the similar states of CLR parsing table into o
6 min read
Compiler Design SLR(1) Parser Using Python
Prerequisite: LR Parser, SLR Parser SLR (1) grammar SLR stands for Simple LR grammar. It is an example of a bottom-up parser. The "L" in SLR represents the scanning that advances from left to right and the "R" stands for constructions of derivation in reverse order, and the “(1)” represents the number of input symbols of lookahead. Shift and Reduce
15+ min read
Problem on LR(0) parser
Prerequisite: LR Parser. The LR parser is an efficient bottom-up syntax analysis technique that can be used for a large class of context-free grammar. This technique is also called LR(0) parsing.L stands for the left to right scanningR stands for rightmost derivation in reverse0 stands for no. of input symbols of lookahead. Augmented grammar :If G
4 min read
Predictive Parser in Compiler Design
In this, we will cover the overview of Predictive Parser and mainly focus on the role of Predictive Parser. And will also cover the algorithm for the implementation of the Predictive parser algorithm and finally will discuss an example by implementing the algorithm for precedence parsing. Let’s discuss it one by one. Predictive Parser :A predictive
2 min read
SLR Parser (with Examples)
LR parsers is an efficient bottom-up syntax analysis technique that can be used to parse large classes of context-free grammar is called LR(k) parsing. L stands for left-to-right scanningR stands for rightmost derivation in reversek is several input symbols. when k is omitted k is assumed to be 1. Advantages of LR parsing LR parsers handle context-
4 min read
Difference between Top down parsing and Bottom up parsing
There are 2 types of Parsing techniques present parsing, the first one is Top-down parsing and the second one is Bottom-up parsing. Top-down parsing is a parsing technique that first looks at the highest level of the parse tree and works down the parse tree by using the rules of grammar while Bottom-up Parsing is a parsing technique that first look
2 min read
Viable Prefix in Bottom-up Parsing
Viable Prefix is a prefix of a right-sentential form that does not continue past the right end of the rightmost handle of that sentential form. This clearly means that a viable prefix has a handle at its rightmost end.Not all prefixes of right sentential form can appear on the stack of a shift reduce parser. This can be shown with the help of follo
3 min read
Bottom-up or Shift Reduce Parsers | Set 2
In this article, we are discussing the Bottom Up parser. Bottom-up Parsers / Shift Reduce Parsers Build the parse tree from leaves to root. Bottom-up parsing can be defined as an attempt to reduce the input string w to the start symbol of grammar by tracing out the rightmost derivations of w in reverse. Eg. Classification of Bottom-up Parsers: A ge
6 min read
Working of Compiler Phases with Example
In this article, we are going to cover an overview that how we can each compiler phase works individually with the help of an example. Let's discuss one by one. Pre-requisite - Introduction to compiler phases You will see how compiler phases like lexical analyzer, Syntax analyzer, Semantic Analyzer, Intermediate code generator, code Optimizer, and
3 min read
Working of Lexical Analyzer in compiler
In this article, we are going to cover how the lexical analyzer works and will also cover the basic architecture of lexical analyzer. Let's discuss one by one. Pre-requisite - Introduction to Lexical Analyzer Lexical Analyzer : It is the first phase of a compiler is known as Scanner (It's scan the program).Lexical Analyzer will divide the program i
2 min read
Private bytes, Virtual bytes, Working set
In this article, we are going to understand private bytes, virtual bytes, and working sets. Private Bytes :As a result of completely paging out the process's private memory footprint to swap, Private Bytes summarizes the amount of RAM allocated to the process (though not necessarily used). Process executables use Private Bytes only to request memor
2 min read
Working of ISO-OSI Model
The ISO-OSI (International organization of Standardization - Open System Interconnection) says to group together the functions which are related to each other. The Functions in OSI Model that are needed for proper communication can be divided into 2 types :- 1. Mandatory Functions: Here the implementation of the functions is not optional, i.e., it
7 min read
DBMS Tutorial – Learn Database Management System
Database Management System is a software or technology used to manage data from a database. Some popular databases are MySQL, Oracle, MongoDB, etc. DBMS provides many operations e.g. creating a database, Storing in the database, updating an existing database, delete from the database. DBMS is a system that enables you to store, modify and retrieve
7 min read
Operating System Tutorial
An Operating System(OS) is software that manages and handles the hardware and software resources of a computer system. It provides interaction between users of computers and computer hardware. An operating system is responsible for managing and controlling all the activities and sharing of computer resources. An operating system is a low-level Soft
6 min read
Types of Operating Systems
An Operating System performs all the basic tasks like managing files, processes, and memory. Thus operating system acts as the manager of all the resources, i.e. resource manager. Thus, the operating system becomes an interface between the user and the machine. It is one of the most required software that is present in the device.  Operating System
10 min read
TCP/IP Model
The TCP/IP model is a fundamental framework for computer networking. It stands for Transmission Control Protocol/Internet Protocol, which are the core protocols of the Internet. This model defines how data is transmitted over networks, ensuring reliable communication between devices. It consists of four layers: the Link Layer, the Internet Layer, t
13 min read
What is OSI Model? - Layers of OSI Model
OSI stands for Open Systems Interconnection, where open stands to say non-proprietary. It is a 7-layer architecture with each layer having specific functionality to perform. All these 7 layers work collaboratively to transmit the data from one person to another across the globe. The OSI reference model was developed by ISO - 'International Organiza
15+ min read
Types of Network Topology
Network topology refers to the arrangement of different elements like nodes, links, and devices in a computer network. It defines how these components are connected and interact with each other. Understanding various types of network topologies helps in designing efficient and robust networks. Common types include bus, star, ring, mesh, and tree to
11 min read
ACID Properties in DBMS
A transaction is a single logical unit of work that accesses and possibly modifies the contents of a database. Transactions access data using read and write operations. In order to maintain consistency in a database, before and after the transaction, certain properties are followed. These are called ACID properties. For those looking to master thes
6 min read
Introduction of ER Model
Peter Chen developed the ER diagram in 1976. The ER model was created to provide a simple and understandable model for representing the structure and logic of databases. It has since evolved into variations such as the Enhanced ER Model and the Object Relationship Model The Entity Relational Model is a model for identifying entities to be represent
10 min read
Normal Forms in DBMS
Normalization is the process of minimizing redundancy from a relation or set of relations. Redundancy in relation may cause insertion, deletion, and update anomalies. So, it helps to minimize the redundancy in relations. Normal forms are used to eliminate or reduce redundancy in database tables. Normalization of DBMSIn database management systems (
12 min read
Article Tags :
three90RightbarBannerImg