Consider the following two sets of LR(1) items of an LR(1) grammar. X → c.X, c/d           X → c.X, $ X → .cX, c/d           X → .cX, $ X → .x, c/d             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.

Consider the following two sets of LR(1) items of an LR(1) grammar. X → c.X, c/d           X → c.X, $ X → .cX, c/d           X → .cX, $ X → .x, c/d             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. Correct Answer 1, 2, 3 and 4

The correct answer is option 4.

Key Points

1. Cannot be merged since lookaheads are different.

False, We can find the LALR stage by merging LR(1) states that have the same set of the first component. We can take the union of lookahead symbol of the respective item. The given LR (1) items can be merged as, 

X → c.X, c/d/$

X → .cX, c/d/$  

X → .x, c/d/$   

2. Can be merged but will result in S-R conflict.

3. Can be merged but will result in R-R conflict.

The given items have no reduced entry(means dot at end of the production) then there is no S-R conflict and R-R conflict in the given grammar. So clearly it says both option 2 and 3 are false. 

4. Cannot be merged since goto on c will lead to two different sets. 

False, Because goto is carried on Non-terminals symbols, not on terminal symbols, and c is a terminal symbol.

Hence the correct answer is 1, 2, 3 and 4.

Additional Information

Checking LALR conflicts:

Shortcut:

[ alt="F1 Raju Madhuri 29.05.2021 D11" src="//storage.googleapis.com/tb-img/production/21/05/F1_Raju_Madhuri_29.05.2021_D11.png" style="width: 185px; height: 137px;">

Let's consider the production A → αaβ and B→α and a,b are lookaheads of the grammar. Then S-R conflicts will occur when one production with reducing production and another one is a shift production. This will make the conflict when shifting terminal and lookahead are same then parsing table has multiple entries. And R-R conflicts have two productions with the same lookaheads.

  • If there is no S-R conflict in LR(1) state it never be reflected in the LALR(1) parser.
  • If there is no R-R conflict in LR(1) state it may be R-R conflict in LALR(1) parser.
  • The parse generates tool 'YAAC' uses LALR(1) parsing algorithm. 

Related Questions

Assume that the SLR parser for a grammar G has n1 states and the LALR parser for G has n2 states. Hence which one is true?
Assume that the SLR parser for a grammar G has n1 states and the LALR parser for G has n2 states.
LALR in LALR parser stands for:
An LALR(1) parser for a grammar can have shift-reduce (S-R) conflicts if and only if ___________