Predicting the next production

The two Ls refer to left-to-right input and a leftmost derivation. When expanding a nonterminal, the parser predicts a production from upcoming input and proceeds through its components.

A predictive table indexes choices by nonterminal and lookahead. For an LL(1) grammar, an applicable cell has at most one production. An empty cell indicates an error; several alternatives mean the available information does not determine a unique prediction.

References: [1]

Empty derivations affect prediction

FIRST describes possible starting terminals, but a nullable fragment can disappear, making following input relevant. FOLLOW captures terminals that can occur after a nonterminal and helps select empty productions.

These sets are computed by propagating grammar facts to a fixed point. They support static construction of predictive decisions rather than guessing from previously executed inputs. Grammar changes require rechecking the table for conflicts.

References: [1]

Recursive and table-driven implementations

Predictive recursive descent can represent rules as procedures, while a table-driven implementation keeps pending work on an explicit stack. Grammars can need transformations such as removing left recursion or factoring shared prefixes.

Additional lookahead does not solve every grammar problem: LL(k) remains a restricted class. Suitability follows the productions and prediction requirements, not simply the presence of nested parentheses or recursive implementation code.

References: [1] [2]