1. Gyanastra
  2. Compiler Design
  3. Comparison of Parsers
  4. Top-Down Parsers Without Backtracking: Recursive and Non-Recursive Descent
Free lesson, no account needed 3 min read 11 practice questions after it
Asked in past papers8 times
  • GATE CSE2026200720001991
  • ISRO20162015
  • UGC NET20162007

Compiler Design · Comparison of Parsers

Top-Down Parsers Without Backtracking: Recursive and Non-Recursive Descent

Overview

Top-down parsers without backtracking come in two forms: recursive descent and non-recursive (table-driven) descent, both belonging to the LL(1) class. To build any of them, the grammar must first be cleaned of left recursion, non-determinism and ambiguity.

Key concepts

  • Recursive descent parser — a parser in which a recursive function is written for every production of the grammar; the name comes from this recursive structure.
  • Non-recursive descent parser — the table-driven form of the same class, i.e. the LL(1) parser.
  • LL(1) class — the class to which both recursive descent and non-recursive descent parsers belong; it is exactly the set of top-down parsers without backtracking.
  • Left recursion — must be absent from the grammar; if present, it must be eliminated before the parser is constructed.
  • Non-determinism — non-deterministic grammars are not allowed; a grammar with non-determinism must be left factored.
  • Ambiguity — an ambiguous grammar must not be used to build any parser of this class, with one exception (the operator precedence parser).

How it works

To construct a top-down parser without backtracking, the grammar must satisfy these restrictions:

  1. No left recursion — if the grammar has left recursion, eliminate it before constructing the parser.
  2. No non-determinism — non-deterministic grammars are not allowed; if the grammar has non-determinism, left factor it.
  3. No ambiguity — an ambiguous grammar is not allowed for any of these parsers, except for the operator precedence parser.

Comparison

ParserAccepts ambiguous grammar?
Top-down parsers without backtracking (recursive descent, non-recursive descent / LL(1))No
Operator precedence parserYes — the only parser that can parse ambiguous grammars

Revision summary

  • Top-down parsers without backtracking = recursive descent (one recursive function per production) + non-recursive descent (LL(1), table-driven).
  • Both forms belong to the LL(1) class.
  • Left recursion must be eliminated; non-determinism must be removed by left factoring.
  • Ambiguous grammars are rejected for all parsers of this class.
  • Trap: the ban on ambiguity has exactly one exception — the operator precedence parser, the only parser that can parse ambiguous grammars.

Previous-year exam insights

  • A top-down parser builds the parse tree from the root downward and traces out a leftmost derivation of the input (it expands the leftmost non-terminal at each step); a bottom-up parser traces a rightmost derivation in reverse.
    Asked inGATE 2000ISRO 2016
  • Recursive descent parsing is a top-down (predictive) parsing technique; LR, SLR, LALR and operator precedence parsers are bottom-up parsers.
    Asked inGATE 2007ISRO 2015ISRO 2016UGC NET 2016
  • Top-down parsers are called predictive parsers because they predict which production to apply (which next tokens/next lower level of the parse tree will be produced) by looking at the next input token, without backtracking.
    Asked inUGC NET 2007
  • A grammar is LL(1) only if it is unambiguous, has no left recursion, and is left-factored (no common prefixes causing multiple entries in an LL(1) table cell); being left-recursive or requiring backtracking disqualifies it.
    Asked inGATE 2026
  • Recursive descent parsing cannot be used for a grammar with left recursion, since the corresponding recursive procedure would call itself without consuming input, causing infinite recursion.
    Asked inGATE 1991
  • An ambiguous grammar can never be LL(k) or LR(k) for any k; ambiguity must be eliminated before any deterministic parsing table can be built.
    Asked inUGC NET 2016
Pages 1–2 of 2