The Gateway to Computer Science Excellence

+16 votes

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:

- $n_1 < n_2 < n_3$
- $n_1 = n_3 < n_2$
- $n_1 = n_2 = n_3$
- $n_1 \geq n_3 \geq n_2$

+26 votes

Best answer

+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)

Answers would be (B) n1=n3<n2

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)

Answers would be (B) n1=n3<n2

+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 .

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 ?

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 ?

r : S->(S)

r2: S->a

both will be placed under follow of S ?

Wont there be a reduce reduce conflict ?

+15

@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

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 .

0

I think, LALR(1) uses canonical collection of LR(1) items, but you have

mentioned that it uses LR(0) items.

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

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

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

- All categories
- General Aptitude 1.9k
- Engineering Mathematics 7.5k
- Digital Logic 2.9k
- Programming and DS 4.9k
- Algorithms 4.3k
- Theory of Computation 6.2k
- Compiler Design 2.1k
- Databases 4.1k
- CO and Architecture 3.4k
- Computer Networks 4.1k
- Non GATE 1.5k
- Others 1.5k
- Admissions 595
- Exam Queries 576
- Tier 1 Placement Questions 23
- Job Queries 72
- Projects 17

50,644 questions

56,507 answers

195,558 comments

101,060 users