The grammar is not suitable for predictive-parsing because the grammar is:
View worked solution
Answer: A
A predictive parser (such as an parser) must be deterministic. This means that for any non-terminal and lookahead symbol, there must be at most one production rule that can be applied. Consequently, no ambiguous grammar can be parsed by a predictive parser.
Let us check if the given grammar is ambiguous:
We can show ambiguity by generating the string () using two different leftmost derivations:
- Derivation 1:
- Derivation 2:
Since the string () has more than one leftmost derivation (and thus multiple distinct parse trees), the grammar is ambiguous. Therefore, it is not suitable for predictive parsing.
Free practice · Your answers on this page are not saved.
