Syntax analysis

Recursive Descent with Backtracking

Step through recursive-descent parsing as it tries each production in order, matches tokens, and backtracks.

  • Lecture reference: Top-Down Parsing · slides 2–35
Alternatives are tried in the order written.
Terminals of the grammar, separated by spaces.

Open this grammar in Context-Free Grammars, Predictive Recursive Descent or LL(1) Parsing Table

Lecture reference: Top-Down Parsing · slides 4–16

Start with the top-level non-terminal E and try the rules for E in order. T → int and T → int * T do not match (, so each is removed again; T → ( E ) matches.

  • With backtracking accept

    6 productions tried 2 backtracks

  • bool functions accept

    6 productions tried 2 backtracks

( int ) is a sentence of the grammar.

Steps every try, match and mismatch

Step 1 of 12
Try E → T

Parse tree

  • Current node
  • Matched terminal

Grammar rules are tried in this order

E → T (being tried)| T+E
T → int | int*T | (E)

Token stream

Fringe
New fringe

The leaves of the tree: matched tokens, the leftmost non-terminal (marked), the rest.

Tries 1 of 6 tried · 0 of 2 backtracks