Consider the following two sets of LR(1) items of an LR(1) grammar. X → c.X,…

20132013

Consider the following two sets of LR(1) items of an LR(1) grammar.

X → c.X, c/d    X → .cX, c/d

X → .d, c/d      X → c.X, $

X → .cX, $       X → .d, $

Which of the following statements related to merging of the two sets in the corresponding LALR parser is/are FALSE?

1. Cannot be merged since look aheads are different.

2. Can be merged but will result in S-R conflict.

3. Can be merged but will result in R-R conflict.

4. Cannot be merged since \(goto \) on \(c\) will lead to two different sets.

  1. A.

    1 only

  2. B.

    2 only

  3. C.

    1 and 4 only

  4. D.

    1, 2, 3 and 4

Attempted by 95 students.

Show answer & explanation

Correct answer: D

Key idea: LALR merges states that have the same core (same items and dot positions); lookahead sets are then unioned.

  • Statement 1 is false: differing lookaheads do not prevent merging because LALR uses the core to decide merges.

  • Statements 2 and 3 are false: the merged state has no completed (dot-at-end) items, so there is no reduce action in that state to conflict with a shift or with another reduce.

  • Statement 4 is false: goto on 'c' from each original LR(1) state would produce the same core (only lookaheads differ). That does not prohibit merging; LALR will merge the cores and union the lookaheads.

Conclusion: All four statements are false, so the correct answer is the choice that states '1, 2, 3 and 4'.

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

Explore the full course: Gate Guidance By Sanchit Sir