Consider the canonical LR(0) parsing of the grammar: Which one of the…

2026

Consider the canonical LR(0) parsing of the grammar:

image.png

Which one of the following options gives the number of shift-reduce conflicts that will occur in the 𝐿𝑅(0) ACTION table?

  1. A.

    2

  2. B.

    3

  3. C.

    4

  4. D.

    5

Attempted by 9 students.

Show answer & explanation

Correct answer: D

Construct the LR(0) item sets and count the states that contain both a completed item, which gives a reduce action, and an item that shifts a terminal.

1. For A → aA | ε, the initial state and the state reached after shifting a both contain A → · and also have a shift on a. This gives 2 shift-reduce conflicts.
2. After A is recognized, the analogous C states contain C → · and also have a shift on c. This gives 2 more shift-reduce conflicts.
3. For B → bB | b, the state reached after shifting b contains B → b · as a reduce item and also has a shift on b from B → · bB / B → · b. This gives 1 more shift-reduce conflict.

Total conflicts = 2 + 2 + 1 = 5.
Therefore, option D is correct.

Explore the full course: Gate Guidance By Sanchit Sir