Recursive Descent Parser — Step by Step
Watch a top-down parser build its tree in pre-order, depth-first order. Every production saves the input position; a failed choice restores that position before the next production is tried.
Try your own grammar
ASCII syntax only: use ->, |, and epsilon. A name that appears on a left-hand side is a nonterminal; every other symbol is a terminal. Use id and num for token classes. Punctuation terminals are one character each.
← → step · Space play/pause
Step 0 of 0
Now
Ready to parse.
Ready
The rules
Grammar
Scanner output
Input tape
0 comparisons
0 rewinds
0 max depth
Built top down
Working parse tree
active
matched
abandoned
Slide algorithm
Parser pseudocode
Parser pseudocode
parse(A):for each A → X₁ … Xₖ:save ← input positionfor each Xᵢ in the RHS:if nonterminal: parse(Xᵢ)else if Xᵢ = lookahead:advance inputelse: this production failsif every Xᵢ succeeded: return 1input position ← save// try the next productionreturn 0
Runtime state
Call stack
Call stack
No active calls
Saved input positions
Backtrack checkpoints
Backtrack checkpoints
No saved positions
Most recent first
Click an event to jump to it