The grammar S \(\to\) aSa|bS|c is
2010
The grammar S \(\to\) aSa|bS|c is
- A.
LL(1) but not LR(1)
- B.
LR(1) but not LR(1)
- C.
Both LL(1) and LR(1)
- D.
Neither LL(1) nor LR(1)
Attempted by 138 students.
Show answer & explanation
Correct answer: C
Key insight: the three alternatives for S start with different terminals, so one-token lookahead suffices.
Compute FIRST sets for the alternatives of S:
aSa has FIRST = {a}
bS has FIRST = {b}
c has FIRST = {c}
Because these FIRST sets are pairwise disjoint, a single lookahead token determines which production to use, so the grammar is LL(1).
Every LL(1) grammar is also LR(1), so the grammar is LR(1) as well.
Therefore the correct characterization is: Both LL(1) and LR(1).
A video solution is available for this question — log in and enroll to watch it.