• edited by
20,879 views
70 70 votes

Consider the following two sets of $\textsf{LR(1)}$ items of an $\textsf{LR(1)}$ grammar.$ $\begin{array}{l|l}
X \rightarrow c.X, c∕d &X → c.X, \$\\
X \rightarrow .cX, c∕  d& X → .cX, \$\\
X \rightarrow .d, c∕ d & X → .d, \$
\end{array}$ $Which of the following statements related to merging of the two sets in the corresponding $\textsf{LALR}$ parser is/are FALSE?

  1. Cannot be merged since look aheads are different.
  2. Can be merged but will result in $\textsf{S-R}$ conflict.
  3. Can be merged but will result in $\textsf{R-R}$ conflict.
  4. Cannot be merged since $\textsf{goto}$ on $c$ will lead to two different sets.
  1. $1$ only      
  2. $2$ only      
  3. $1$ and $4$ only      
  4. $\text{1, 2, 3}$ and $4$

6 Answers

Best answer
90 90 votes

The TRUE statements are about merging of two states for $\textsf{LALR(1)}$ parser from $\textsf{LR(1)}$ parser.

  1. The given two states can be merged because kernel of these are same, look aheads don't matter in merging.
  2. The two states do not contain shift reduce conflict, so after merging the merged states cannot contain any $\textsf{S-R}$ conflict.
  3. There is no final item in both states, so no $\textsf{R-R}$ conflict.
  4. Merging of states does not depend on further $\textsf{GOTO}$ part on any terminal.

Therefore,  all the given statements in question are FALSE.

Option (D) is correct.

• edited by
9 9 votes

after merging their are no final item so no posiblity of any type of conflict . bcz S-R,R-R conflicts r check over final item so option 2 and 3 are totaly wrong . and option 1 also wrong bcz merging can be possible bcz its does not  depend upon look ahead symbol.and option 4. so D is the option 

5 5 votes
Option A, B and D are clearly false, following are reasons
-Since merging don't depend on lookahead
-Due to the merging SR conflict never occurs
-And merging also don't depend on Goto part.
RR conflict may be occur after merging but in question no RR conflict even after merging.
So claerly option D is right choice.
1 1 vote
  • Both sets have the exact same $\text{LR}(0)$ core items $\{X \rightarrow c.X, \; X \rightarrow .cX, \; X \rightarrow .d\}$, so they can be merged in an $\text{LALR}$ parser by taking the union of their lookaheads $\{c, d, \$\}$.

  • Statement 1 is FALSE because different lookaheads do not prevent merging; merging specifically combines identical cores having different lookaheads.

  • Statement 2 is FALSE because none of the items are completed reduce items (the dot is not at the end), so no Shift-Reduce (S-R) conflict can occur.

  • Statement 3 is FALSE because without completed reduce items, a Reduce-Reduce (R-R) conflict is impossible.

  • Statement 4 is FALSE because goto transitions on non-terminals or terminals with identical cores are also merged consistently into a single state.

Correct Option: D. 1, 2, 3 and 4

0 0 votes
The two sets in LR(1) items can be merged if they only differ with look aheads symbols, so statement 1 is false.
In the given LR(1) items there is not any reduce move, so after merging it will not have SR conflict and hence statement 2 and statement 3 are false.
Statement 4 is also wrong, because goto is carried on Non-Terminals symbols, not on terminal symbols, and c is a terminal symbol.
Hence all statements are false.
0 0 votes

 

final result :
X→c.X,c∕d​/$

X→.cX,c∕d​/$

X→.d,c∕d​/$

  1. Cannot be merged since look aheads are different.....FALSE
    reason lookhead does affect the mergering
  2. Can be merged but will result in S-RS-R conflict......FALSE
    reason The two states do not contain shift reduce conflict, so after merging the merged states cannot contain any S-RS-R conflict
  3. Can be merged but will result in R-RR-R conflict....false
    reason: There is no final item in both states, so no R-RR-R conflict.
  4. Cannot be merged since gotogoto on cc will lead to two different sets....FALSE
    reason : Merging of states does not depend on further GOTOGOTO part on any terminal.

 

Answer:
Position:
Show:

Related questions

126 126 votes
18 answers 18 answers
64.8k
64.8k views
Arjun asked Sep 23, 2014
64,831 views
What is the maximum number of reduce moves that can be taken by a bottom-up parser for a grammar with no epsilon and unit-production (i.e., of type $A \rightarrow \epsilo...
22 22 votes
3 answers 3 answers
12.1k
12.1k views
go_editor asked Apr 21, 2016
12,050 views
The following code segment is executed on a processor which allows only register operands in its instructions. Each instruction can have atmost two source operands and on...
55 55 votes
6 answers 6 answers
44.9k
44.9k views
Arjun asked Sep 24, 2014
44,927 views
The following code segment is executed on a processor which allows only register operands in its instructions. Each instruction can have atmost two source operands and on...
38 38 votes
2 answers 2 answers
13.7k
13.7k views
go_editor asked Feb 14, 2015
13,663 views
Among simple LR (SLR), canonical LR, and look-ahead LR (LALR), which of the following pairs identify the method that is very easy to implement and the method that is the ...