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?

- Cannot be merged since look aheads are different.
- Can be merged but will result in S-R conflict.
- Can be merged but will result in R-R conflict.
- Cannot be merged since goto on c will lead to two different sets.

**(A)** 1 only

**(B)** 2 only

**(C)** 1 and 4 only

**(D)** 1, 2, 3, and 4

**Answer:** **(D)** **Explanation:** The given two LR(1) set of items are :

X -> c.X, c/d X -> .cX, c/d X -> .d, c/d and X -> c.X, $ X -> .cX, $ X -> .d, $

The symbols/terminals after the comma are Look-Ahead symbols.

These are the sets of LR(1) ( LR(1) is also called CLR(1) ) items.

The LALR(1) parser combines those set of LR(1) items which are identical with respect to their 1st component but different with respect to their 2nd component.

In a production rule of a LR(1) set of items, ( A -> B , c ) , A->B is the 1st component , and the Look-Ahead set of symbols, which is c here, is the second component.

Now we can see that in the sets given, 1st component of the corresponding production rule is identical in both sets, and they only differ in 2nd component ( i.e. their look-ahead symbols) hence we can combine these sets to make a a single set which would be :

X -> c.X, c/d/$ X -> .cX, c/d/$ X -> .d, c/d/$

This is done to reduce the total number of parser states.

Now we can check the statements given.

Statement 1 : The statement is false, as merging has been done because 2nd components i.e. look-ahead were different.

Statement 2 : In the merged set, we can’t see any Shift-Reduce conflict ( because no reduction even possible, reduction would be possible when a production of form P -> q. is present)

Statement 3 : In the merged set, we can’t see any Reduce-Reduce conflict ( same reason as above, no reduction even possible, so no chances of R-R conflict )

Statement 4: This statement is also wrong, because goto is carried on Non-Terminals symbols, not on terminal symbols, and c is a terminal symbol.

Thus, all statements are wrong, hence option D.

Quiz of this Question

## Recommended Posts:

- GATE | GATE CS 2013 | Question 1
- GATE | GATE CS 2013 | Question 2
- GATE | GATE CS 2013 | Question 3
- GATE | GATE CS 2013 | Question 4
- GATE | GATE CS 2013 | Question 65
- GATE | GATE CS 2013 | Question 6
- GATE | GATE CS 2013 | Question 7
- GATE | GATE CS 2013 | Question 8
- GATE | GATE CS 2013 | Question 65
- GATE | GATE CS 2013 | Question 65
- GATE | GATE CS 2013 | Question 11
- GATE | GATE CS 2013 | Question 12
- GATE | GATE CS 2013 | Question 13
- GATE | GATE CS 2013 | Question 14
- GATE | GATE CS 2013 | Question 15
- GATE | GATE CS 2013 | Question 65
- GATE | GATE CS 2013 | Question 17
- GATE | GATE CS 2013 | Question 18
- GATE | GATE CS 2013 | Question 19
- GATE | GATE CS 2013 | Question 65