Consider the following grammar G
Where , , and are non-terminal symbols, , and are terminal symbols. Which of the following statement(s) is/are correct?
S1: LL(1) can parse all strings that are generated using grammar G
S2: LR(1) can parse all strings that are generated using grammar G
View worked solution
Answer: D
A grammar is ambiguous if there exists a string that has more than one distinct leftmost derivation (or parse tree).
Let us consider the string generated by the grammar :
- Derivation 1:
- Derivation 2:
Since the string has two distinct leftmost derivations, the grammar is ambiguous.
An ambiguous grammar can never be parsed by any deterministic parser, such as , , , or .
Therefore:
- S1 is incorrect: cannot parse the grammar.
- S2 is incorrect: cannot parse the grammar.
Thus, neither S1 nor S2 is correct.
Free practice · Your answers on this page are not saved.
