...
GATE 2008
March 14, 2025
GATE 2008
March 14, 2025
GATE 2008
March 14, 2025
GATE 2008
March 14, 2025

GATE 2008

Question 55

An LALR(1) parser for a grammar G can have shift-reduce (S-R) conflicts if and only if

A
the SLR(1) parser for G has S-R conflicts
B
the LR(1) parser for G has S-R conflicts
C
the LR(0) parser for G has S-R conflicts
D
the LALR(1) parser for G has reduce-reduce conflicts
Question 55 Explanation: 
LALR(1) parser is obtained by minimizing the LR(1) parser and hence they both uses LR(1) items. Now consider if LR(1) parser has SR conflict, for ex:
Consider a state in LR(1) parser:
S-> x.yA, a
A-> x. , y
This has both shift and reduce conflict on symbol “y”.
Since LR(1) already has SR conflict , so resulting LALR(1) (after merging) will also have SR conflict.
Now if LR(1) doesn’t have SR conflict then it is guaranteed that the LALR(1) will never have SR conflict. The reason behind this is, as we merge those state only which has same set of canonical items except look ahead and the LR(1) canonical items has DFA (means from one state to other state the transition is from unique symbol) , so after merging also we will never see any shift conflict, only reduce-reduce may occur.
Hence An LALR(1) parser for a grammar G can have shift-reduce (S-R) conflicts if and only if the LR(1) parser for G has S-R conflicts.
Correct Answer: B
Question 55 Explanation: 
LALR(1) parser is obtained by minimizing the LR(1) parser and hence they both uses LR(1) items. Now consider if LR(1) parser has SR conflict, for ex:
Consider a state in LR(1) parser:
S-> x.yA, a
A-> x. , y
This has both shift and reduce conflict on symbol “y”.
Since LR(1) already has SR conflict , so resulting LALR(1) (after merging) will also have SR conflict.
Now if LR(1) doesn’t have SR conflict then it is guaranteed that the LALR(1) will never have SR conflict. The reason behind this is, as we merge those state only which has same set of canonical items except look ahead and the LR(1) canonical items has DFA (means from one state to other state the transition is from unique symbol) , so after merging also we will never see any shift conflict, only reduce-reduce may occur.
Hence An LALR(1) parser for a grammar G can have shift-reduce (S-R) conflicts if and only if the LR(1) parser for G has S-R conflicts.

Leave a Reply

Your email address will not be published. Required fields are marked *