# GATE | Quiz for Sudo GATE 2021 | Question 50

• Last Updated : 18 Dec, 2020

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?

Note – This question is multiple select questions (MSQ).
(A) Can be merged since look aheads are different.
(B) Can be merged but will result in S-R conflict.
(C) Can be merged but will result in R-R conflict.
(D) Can be merged since goto on c will lead to two different sets.

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 true, 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 true, because goto is carried on Non-Terminals symbols, not on terminal symbols, and c is a terminal symbol.

Option (B) and (C) are correct.

Quiz of this Question
Please comment below if you find anything wrong in the above post

My Personal Notes arrow_drop_up
Related Articles