Using upcoming tokens to decide

When several structures remain possible, a parser can inspect upcoming tokens before choosing. LLVM’s example checks whether an identifier is followed by an opening parenthesis to distinguish a call from a variable reference.

The unit is a lexical token, not necessarily one source character. A long identifier can be one token, while comments and whitespace follow lexical rules. One-token lookahead therefore does not mean examining only one byte.

References: [1] [2]

Lookahead works with parser state

An LL predictive table combines the expected nonterminal with lookahead. Nullable branches also require information about what can follow, rather than only a literal first token in their own production.

LR parsing combines lookahead with stack state when choosing shifts and reductions. Having input available for a decision does not mean every earlier construct has finished; required reductions can precede advancing that input through the parsing state.

References: [3] [4]

More lookahead has costs and limits

In LL(k), k describes the lookahead needed for prediction. Larger k can distinguish shared prefixes but increases construction and storage complexity; buffering is a separate implementation choice.

Lookahead length alone does not characterize every parser’s power. Grammar transformations, state construction, backtracking, and other strategies matter. Suitability requires the specific algorithm and grammar rather than an assumption that looking farther resolves every ambiguity.

References: [3] [4]