GATE | GATE CS 2013 | Question 65

10 Sep, 2021
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.
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 4Answer: (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.
GATE PYQ - Parsing and SDT (Continued) Part 3 with Joyojyoti Acharya - YouTubeGeeksforGeeks GATE Computer Science17.4K subscribersGATE PYQ - Parsing and SDT (Continued) Part 3 with Joyojyoti AcharyaWatch laterShareCopy linkInfoShoppingTap to unmuteIf playback doesn't begin shortly, try restarting your device.You're signed outVideos you watch may be added to the TV's watch history and influence TV recommendations. To avoid this, cancel and sign in to YouTube on your computer.CancelConfirmMore videosMore videosSwitch cameraShareInclude playlistAn error occurred while retrieving sharing information. Please try again later.Watch on0:000:0040:55 / 52:18•Live•<div class="player-unavailable"><h1 class="message">An error occurred.</h1><div class="submessage"><a href="https://www.youtube.com/watch?v=Sn5eIxvrNBc" target="_blank">Try watching this video on www.youtube.com</a>, or enable JavaScript if it is disabled in your browser.</div></div>Quiz of this Question
GATE-CS-2013
GATE-GATE CS 2013
GATE
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
GATE | GATE-CS-2014-(Set-2) | Question 65
GATE | Sudo GATE 2020 Mock I (27 December 2019) | Question 33
GATE | GATE-CS-2015 (Set 3) | Question 65
GATE | GATE-CS-2014-(Set-3) | Question 65
GATE | GATE CS 2008 | Question 46
GATE | GATE CS 1996 | Question 63
GATE | Gate IT 2005 | Question 52
GATE | GATE-CS-2001 | Question 50
GATE | GATE CS 2012 | Question 18
GATE | GATE CS 2008 | Question 40