Consider the grammar shown below. S → C C C → c C | d The grammar is

2003

Consider the grammar shown below.

S → C C
C → c C | d

The grammar is

  1. A.

    LL(1)

  2. B.

    SLR(1) but not LL(1)

  3. C.

    LALR(1) but not SLR(1)

  4. D.

    LR(1) but not LALR(1)

Attempted by 38 students.

Show answer & explanation

Correct answer: A

Answer: The grammar is LL(1).

Reason:

  • Compute FIRST sets: FIRST(C) = {c, d}. For C → c C, FIRST = {c}. For C → d, FIRST = {d}.

  • The two alternatives for C have disjoint FIRST sets ({c} and {d}), so there is no choice conflict when parsing C with one lookahead.

  • For S → C C, each occurrence of C is chosen by the next input token (c or d). There are no ε-productions that could cause FIRST/FOLLOW conflicts.

  • Therefore a predictive parser with one token lookahead can decide every production, so the grammar is LL(1).

Note: Since the grammar is LL(1), it is also SLR(1), LALR(1), and LR(1). Any answer claiming it is not LL(1) or that it is LR(1) but not LALR(1) is therefore incorrect for this grammar.

A video solution is available for this question — log in and enroll to watch it.

Explore the full course: Gate Guidance By Sanchit Sir