in Compiler Design retagged by
696 views
2 votes
2 votes

Consider the following grammar:
$S \rightarrow  L = P \mid P$
$L \rightarrow ^*P \mid id$
$P \rightarrow L$

The above grammar is:

  1. Ambiguous
  2. SLR(1)
  3. LALR(1)
  4. None of the above
in Compiler Design retagged by
by
696 views

4 Comments

SLR(1) parsing table also have RR conflict, check the L->*p. and P->L. reductions we find the follow of both L and P as " * " so RR conflict occured here.
0
0
edited by

@Ashwani Kumar 2 the productions should be S->L.=P (shift move)  and P->L. (reduce move)

you write the second S instead of P.

and also you wrong interpreted the logic, it should be like this :

we first find the follow of S which is  and

then, find the follow of P which is also so same we then got the SR conflict here.

how the follow of S contains ' = '  in this case?

0
0
U have done minor mistake, follow of S is not '=', its for L.

In S-> L.=P, P->L.

Fo(P) = Fo(L)U Fo(S) = {\$,=}

in S->L.=P shift on '=' and in P->L. Reduce on '=' is shift-reduce conflict in SLR(1). While in LALR(1), lookahead P->L. is $ only and shifting on '=', hence no conflicts.
0
0

2 Answers

2 votes
2 votes
Best answer

 there are no conflicts in any states and merging based on lookaheads is also possible. it is LALR(1) grammar.

selected by
1 vote
1 vote
Can someone explain me how this is checked?
by

2 Comments

Please draw the DFA , it is LALR(1) 

Go through this thread :

https://www.facebook.com/groups/core.cs/permalink/1373588902673359/

0
0
The grammar is unambiguous.

The construction of SLR(1) parsing table reveals shift reduce conflict, hence the grammar is not SLR(1).

The grammar is LALR(1) as there is no conflict in LALR(1) parsing table of the grammar.
0
0
Answer:

Related questions