IAE Academy

GATE 2025 CS2 Q.40: solution and answer

GATE 2025 · CS2Q.40 · 2 marks · MCQ

Given a Context-Free Grammar as follows:

Which ONE of the following statements is TRUE?

  1. (A)

    is neither LALR(1) nor SLR(1)

  2. (B)

    is CLR(1), not LALR(1)

  3. (C)

    is LALR(1), not SLR(1)

  4. (D)

    is LALR(1), also SLR(1)

See the question in the paper

Answer and solution

ANSWER

is LALR(1) but not SLR(1), which is option (C).

Official answer: CSource: Official answer key, GATE 2025 CS2 (IIT Roorkee)

  1. Compute the follow set: occurs in and , so .

  2. Start state contains , , , and . On it moves to .

  3. SLR(1) test on : the reduce is placed on every symbol of , and the shift is on c. The entry for c holds both a reduce and a shift, a shift-reduce conflict, so is not SLR(1). (The state reached on then has the same problem on a.)

  4. CLR(1) lookaheads in : this comes only from , so its lookahead is . The reduce is on a and the shift is on c, so there is no conflict.

  5. Reaching after gives . Here comes from , so its lookahead is , and the shift is on a. There is no conflict, so is CLR(1).

  6. LALR(1) merges only CLR(1) states that have identical LR(0) cores. has core and has core . The cores differ, so no states merge and the LALR(1) table equals the CLR(1) table, which is conflict-free.

  7. Hence is LALR(1) (and CLR(1)) but not SLR(1). Option (B) is false because is LALR(1), (A) and (D) are false for the same reason or because is not SLR(1). The answer is (C).

KEY IDEA

SLR(1) reduces on the whole FOLLOW set, while CLR(1) and LALR(1) use the exact lookahead of each item. The two states containing have different LR(0) cores, so LALR(1) merges nothing and keeps the CLR(1) table, which has no conflict.

WATCH OUT FOR

Assuming that the two states holding merge in LALR(1) and create a reduce-reduce or shift-reduce conflict. Their cores differ ( against ), so they stay separate. Another slip is using FOLLOW(A) = {a, c} as the lookahead, which makes it look SLR-conflict-free or CLR-conflicted.

From the GATE 2025 CS2 paper. Every question of this paper · Download the full paper · All 13 Parsing questions, with notes

More Parsing questions