The grammar S \(\to\) aSa|bS|c is

2010

The grammar S \(\to\) aSa|bS|c is

  1. A.

    LL(1) but not LR(1)

  2. B.

    LR(1) but not LR(1)

  3. C.

    Both LL(1) and LR(1)

  4. 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.

Explore the full course: Gate Guidance By Sanchit Sir