# GATE | GATE CS 2013 | Question 65

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.

(A) 1 only
(B) 2 only
(C) 1 and 4 only
(D) 1, 2, 3, and 4

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

My Personal Notes arrow_drop_up
Article Tags :

Be the First to upvote.

Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.