3.2k views

Consider the grammar:

$$S \rightarrow (S) \mid a$$

Let the number of states in SLR (1), LR(1) and LALR(1) parsers for the grammar be $n_1, n_2$ and $n_3$ respectively. The following relationship holds good:

1. $n_1 < n_2 < n_3$
2. $n_1 = n_3 < n_2$
3. $n_1 = n_2 = n_3$
4. $n_1 \geq n_3 \geq n_2$
| 3.2k views
0
no need to construct table just see the answer if it is unique standard relation then it is the answer. If not then make parsing diagram for CLR only because other will be same and extra state made in CLR then option B other wise option C

ans B

Both in SLR(1) and LALR(1), states are the LR(0) items while in LR(1) the states are LR(1) set of items. Number of LR(0) items can never be greater than number of LR(1) items. So, $n_1 = n_3 \leq n_2$, B choice.  If we construct the states for the grammar we can replace $\leq$ with $<$.

by Loyal (5.2k points)
edited by
0
why
+1
@utsab if you try to draw the SLR(1) you would get 6 states and the given grammar is LR(0) so must be SLR(1),LALR(1),CLR(1)/LR(1) now if you try to draw LR(1) table

you would get 7 states and there 2 states will differ by only look ahead symbols

1) s->(.s), &

s->.(s), )

s->.a, )

2)  s->(.s), )

s->.(s), )

s->.a, )    // you can minimizes the number of states by merging them and minimized CLR(1) is known as                     LALR(1) so you will get same number of states as SLR(1)

+1
@arjun sir  in this type of question where grammer are given and

Let the number of states in SLR (1), LR(1) and LALR(1) parsers for the grammar be n1 ,n2 and n3 respectively . so as we know in  general n1=n3<n2   is it valid for any type of given grammer in question  ??  or we go on the basis of given grammer and makes the state transition digram and count the no of states for each parser  and then we will give the answer .
0
n1 = n3 < n2 is  in general true ?
but it could also be n1 = n2 = n3  right ??

We should draw diagram for finding out . Don't we ?
0
@arjun sir , is SLR(1) posible ?

r : S->(S)

r2: S->a

both will be placed under follow of S ?
Wont there be a reduce reduce conflict ?
+18

@Das there will no conflicts in SLR.  Because reductions  will be in two different states.

Although n1=n3 <=  n2 is the general relationship between states.  We must draw the state diagram for CLR to confirm.  Reason behind selecting CLR is,  if we draw it's diagram then we would guess what would happen in SLR and LALR

SLR -  6 states CLR - 10 states LALR -  6 states +1
@pc  kindly check ur clr  it will having 10 states not 8 . and their is no conflict either S-R or R-R
0
@rajan What are the 10 states you are talking about ? Can you show the states ? We can discuss. I think It will be 8 states only.  I didn't account for any conflicts here as the question is interested in olny finding number of states .
+1
yr just see   S->(.S),) on S it will go S->(S.) , )  not on S->(S.),\$
+1
@rajan , ys you are  right ! I corrected my mistake . Thanks for pointing it out :)
+1
no problem bro
0
I think, LALR(1) uses canonical collection of LR(1) items, but you have

mentioned that it uses LR(0) items.
0
Option a and d is wrong since n2 is less than n3, which is not possible

And to choose between b and c draw clr(1) graph you will get same item with different lookahead
0
0

Both in SLR(1) and LALR(1), states are the LR(0) items

I think for LALR(1) it's is LR(1) Items only

Even here also it's written same https://gateoverflow.in/478/gate2008-55