Difference between Recursive Predictive Descent Parser and Non-Recursive Predictive Descent Parser

14 Jul, 2021
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 Predictive Recursive Descent Parser, in which look-ahead symbol unambiguously determines flow of control through procedure body for each non-terminal. The sequence of procedure calls during analysis of an input string implicitly defines a parse tree for input and can be used to build an explicit parse tree, if desired. In recursive descent parsing, parser may have more than one production to choose from for a single instance of input there concept of backtracking comes into play. 
Back-tracking – It means, if one derivation of a production fails, syntax analyzer restarts process using different rules of same production. This technique may process input string more than once to determine right production.Top- down parser start from root node (start symbol) and match input string against production rules to replace them (if matched). 
To understand this, take following example of CFG : 
S -> aAb | aBb
A -> cx | dx
B -> xe 
For an input string – read, a top-down parser, will behave like this. 
It will start with S from production rules and will match its yield to left-most letter of input, i.e. ‘a’. The very production of S (S -> aAb) matches with it. So top-down parser advances to next input letter (i.e., ‘d’). The parser tries to expand non-terminal ‘A’ and checks its production from left (A -> cx). It does not match with next input symbol. So top-down parser backtracks to obtain next production rule of A, (A -> dx). 
Now parser matches all input letters in an ordered manner. The string is accepted. 
2. Non-Recursive Predictive Descent Parser : A form of recursive-descent parsing that does not require any back-tracking is known as predictive parsing. It is also called as LL(1) parsing table technique since we would be building a table for string to be parsed. It has capability to predict which production is to be used to replace input string. To accomplish its tasks, predictive parser uses a look-ahead pointer, which points to next input symbols. To make parser back-tracking free, predictive parser puts some constraints on grammar and accepts only a class of grammar known as LL(k) grammar.  
Predictive parsing uses a stack and a parsing table to parse input and generate a parse tree. Both stack and input contains an end symbol $ to denote that stack is empty and input is consumed. The parser refers to parsing table to take any decision on input and stack element combination. There might be instances where there is no production matching input string, making parsing procedure to fail. 
Difference between Recursive Predictive Descent Parser and Non-Recursive Predictive Descent Parser : 
Recursive Predictive Descent Parser
Non-Recursive Predictive Descent Parser
 
varshagumber28
Compiler Design
Difference Between
GATE CS
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Issues in the design of a code generator
Peephole Optimization in Compiler Design
Directed Acyclic graph in Compiler Design (with examples)
Type Checking in Compiler Design
Difference between Compiler and Interpreter
Class method vs Static method in Python
Difference between BFS and DFS
Difference between var, let and const keywords in JavaScript
Difference Between Method Overloading and Method Overriding in Java
Differences between JDK, JRE and JVM