optional · CSS study notes
Predictive Parsing Using LL(1) Grammars
Definition
Predictive parsing is a top-down, table-driven parsing method that decides which production to apply using only one lookahead token — no backtracking needed — applicable only to LL(1) grammars.
Key Points
- Requirements for LL(1): grammar must not be left-recursive, must be left-factored, and for any two productions A → α | β, FIRST(α) ∩ FIRST(β) = ∅ (and if ε ∈ FIRST(α), then FIRST(β) ∩ FOLLOW(A) = ∅).
- Parsing table M[A, a]: built using FIRST/FOLLOW; entry tells which production to use for non-terminal A when lookahead is terminal a.
- Parser mechanism: uses a stack + input buffer + parsing table; pushes/pops symbols, matching terminals with input and expanding non-terminals per table entries.
- If M[A,a] is empty → syntax error.
Example
For E → T E', E' → + T E' | ε, T → id:
- M[E, id] =
E → T E' - M[E', +] =
E' → + T E' - M[E', $] =
E' → ε
📌 CSS Frequency: High — usually paired with FIRST/FOLLOW as a full numeric question ("construct the LL(1) table and parse the string").
Model Answer (short)
"Predictive (LL(1)) parsing is a backtrack-free, top-down parsing method that uses a parsing table indexed by non-terminal and next input symbol, built from FIRST and FOLLOW sets. It requires the grammar to be free of left recursion and ambiguity for a given lookahead. The parser uses a stack to track pending grammar symbols and matches input tokens against the top of the stack, consulting the table whenever a non-terminal is on top."