# What is Top-Down Parsing Without Backtracking in Compiler Design?

Compiler DesignProgramming LanguagesComputer Programming

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 accessible to write and adequately effective if written in a language that performs the procedure call effectively.

There is a procedure for each non-terminal in the grammar. It can consider a global variable lookahead, influencing 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 implementing 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$.

The parser is controlled by a program that performs as follows − The program decides X the symbol on top of the stack and ‘a’ the current input symbol. These two symbols decide the action of the parser.

There are three possibilities such as

• If X = a = $, the parser terminate and declares successful integration of parsing. • If X =a ≠$, the parser pops X off the stack and advances the input pointer to the next input symbol.
• If X is a non-terminal, the program consults entry M[X, a] of the parsing table M. This entry will be either an X-production of the grammar or an error entry. If M[X, a] = [X→ UVW], the parser replaces X on top of the stack by UVW (with U on top). As output, the grammar does the semantic action associated with this production, which for the time being, it can assume is just printing the production used. If M[X, a] = error, the parser calls an error recovery routine.
Updated on 30-Oct-2021 13:39:01