- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
What is the difference between Backtracking and Non- Backtracking?
Top-Down Parsing with Backtracking
In Top-Down Parsing with Backtracking, Parser will attempt multiple rules or production to discover the match for input string by backtracking at every step of derivation. So, if the used production does not give the input string as needed, or it does not match with the needed string, then it can undo that shift.
Top-Down Parsing without Backtracking
As backtracking looks more powerful by which we can select different alternatives. But backtracking cannot be applied or implemented so easily in parsing. There are two types of Top-Down Parsing without Backtracking, which are as follows −
- Recursive Descent Parser
- Predictive Parser
Recursive Descent Parser
A top-down parser that implements a set of recursive procedures to process the input without backtracking is known as recursive-descent parser, and parsing is known as recursive-descent parsing. The recursive procedures can be simply to write and adequately effectively if written in a language that executes the procedure call effectively.
There is a procedure for each non-terminal in the grammar. It can consider a global variable lookahead, holding the current input token and a procedure match (Expected Token) is the action of recognizing the next token in the parsing process and advancing the input stream pointer, such that lookahead points to the next token to be parsed. Match () is effectively a call to the lexical analyzer to get the next token.
Predictive Parser
Predictive Parser is also known as Non-Recursive Predictive Parsing. A predictive parser is an effective approach of executing recursive-descent parsing by handling the stack of activation records explicitly. The predictive parser has an input, a stack, a parsing table, and an output. The input includes the string to be parsed, followed by $, the right-end marker.
The stack includes a sequence of grammar symbols, preceded by $, the bottom-ofstack marker. Initially, the stack includes the start symbol of the grammar preceded by $. The parsing table is a two-dimensional array M[A, a] where ‘A’ is a nonterminal, and ‘a’ is a terminal or the symbol $.
Let us see the comparison between Top-Down Parsing with Backtracking and Top-Down Parsing without Backtracking
Top-Down Parsing with Backtracking | Top-Down Parsing without Backtracking |
---|---|
The parser can try all alternatives in any order till it successfully parses the string. | The parser has to select correct alternatives at each step. |
Backtracking takes a lot of time, i.e., exponential time to perform the parsing. | It takes less time. |
A Grammar can have left recursion. | Left Recursion will be removed before doing parsing. |
A lot of overhead will be there while undoing things. | It can run less overhead. |
Information, once inserted, will be removed from the symbol table while backtracking. | Information will not be removed. |
It can be difficult to find where actually error has occurred. | It can easy to find the location of the error. |
- Related Articles
- What is recursion & backtracking in Python?
- Introduction to Backtracking
- Introduction to Backtracking Algorithms
- What is Top-Down Parsing with Backtracking in compiler design?
- What is Top-Down Parsing Without Backtracking in Compiler Design?
- C / C++ Program for Subset Sum (Backtracking)
- A backtracking approach to generate n bit Gray Codes ?
- C Program for Rat in a Maze - Backtracking-2?
- What is the difference between uniform and non-uniform motion ?
- What is the difference between Volatile and Non-Volatile substances?
- How to find all the permutation of the string by backtracking using C#?
- How to implement backtracking for a climbing stairs practice in JavaScript?
- How to find the power of any given number by backtracking using C#?
- How to find the target sum from the given array by backtracking using C#?
- What is the difference between "strict" and "non-strict" modes of JavaScript?
