Consider the grammar below A → BB B → bB | c B → c
Consider the grammar below
A → BB
B → bB | c
B → c
Answer: A. Both LL(1) and LR(1) — Grammar: A → B B , B → bB | c Compute FIRST sets: FIRST(B) = {b, c}. There is no ε-production for B. LL(1) check: The two alternatives for B start with…
- A.
Both LL(1) and LR(1)
- B.
Neither LL(1) nor LR(1)
- C.
LR(1)
- D.
LL(1)
Attempted by 31 students.
Show answer & explanation
Correct answer: A
Grammar: A → B B , B → bB | c
Compute FIRST sets:
FIRST(B) = {b, c}. There is no ε-production for B.
LL(1) check:
The two alternatives for B start with different terminals (b and c), so their FIRST sets are disjoint. A has a single production A → B B, so there are no competing productions for A.
Conclusion about LL(1):
Because alternatives for each nonterminal have disjoint FIRST sets and no ε is involved, the grammar is LL(1).
LR(1) check:
LR(1) parsers are more general than LL(1); any LL(1) grammar will have LR(1) item sets with no shift/reduce or reduce/reduce conflicts. Therefore this grammar is also LR(1).
Final answer: the grammar is both LL(1) and LR(1).