in Compiler Design retagged by
2,210 views
0 votes
0 votes
Let G be any grammar with the following productions:

X → X + Y | Y

Y → Y * Z | Z

Z → (X)

Z → id

If LR(!) parser is used to parse the above grammar, then total how many look-a-heads are present for the item X → >Y and Z → .id in the initial state _____________.

Please explain your answer.
in Compiler Design retagged by
by
2.2k views

37 Comments

Yes it will be 3as you shown
0
0
Yes I'm also getting total 5
0
0
Me too $5$.
0
0
then it's Wrong Answer by ME, error in almost every test.
0
0
no it will be {$} for X->.Y and also for X->X+Y
0
0
yes you are right + will come in lookahead. Solution is wrong.
1
1
Hey adarsh in same state again we have to do closure of stmt X->.X+Y{$}
so we get

X->.X+Y{+} and X->.Y{+}
and after combine we
X->.X+Y{$,+} and X->.Y{$,+}
Explain me if I am wrong
0
0

You are right @Ravi kumar singh. As it is left recursive we have to find its closure again which will add + to lookahead

0
0
i missd this part thanks ravi u r right.thanks
0
0

@Hemanth_13 Total number of look ahead should be 2+3 = 5 right ?? How is it 3 ?

1
1
Sorry I just considered for Z->.id  ,$/+/* only.
0
0
0
0
So, final ans $5$

right?
1
1
Yes it should be 5.
1
1
I am getting only 4

X-->.Y {dollar,+}
 
Z-->.id {dollar,*}

how you all got 5. I think I am missing something. please explain.
0
0

X->.Y ,$/+

Z->.id,$/+/*  @Gupta731

1
1
Yes ans is 5 thanks I also missed 1 lookahead got it now.
0
0
Actually we have 3 different lookaheads as it is specified how many lookaheads the answer should  be 5 if it is specified how many different lookaheads then answer will be 3.

Am I correct?
0
0
but hemanth it is asking for particular items right? so it will still different for both the items .isnt so?
0
0

@adarsh_1997 Yes you are right. After seeing the answer I just thought in what way the answer could be 3.

0
0
It is a duplicate question

Answer is 5

X-->.Y{$$,+}

Z--> .id{$,+,*}
0
0
5 will be the answer. The answer in ME test is 3 which is wrong

{+,\$,*} as Look Ahead for Z->.id

and {\$,+} for X→.Y
0
0
The answer is 5. They have provided wrong answer.
1
1
Yeah it should be $5$. 2 for $X \rightarrow .Y$ and 3 for $Z \rightarrow .id$.
1
1
yes that's what i've got but i don't know why they incorrect the 5.
0
0

@ghostman23111   madeeasy have 1 solution incorrect for almost every test. so better trust your intuition and judgement.

1
1
2 +3 = 5

for X->.Y +/\$

for Z->.id */+/\$
1
1
This question is from made easy test na??. But I think they have given wrong answer
0
0
Yes, it is from ME test series.

Are you sure about the answer?
0
0

@VikramRB Yeah! I am sure.

 

0
0
Thanks for the answer Kunal.
0
0
0
0
why $5$ lookaheads?

here lookaheads are $,+, *

what other two?
0
0

@srestha mam since the production are same and carry lookahead are diff ,we can merge both of them. 

because if they are not merged a production will be added two times. check my answer below

0
0

@adarsh_1997 here look ahead will be only 3

$,*,+

check this https://gateoverflow.in/184648/m-e-test

0
0
please provide the detail solution, unable to find the look ahead.
0
0

$X' \rightarrow .X,  \$ $

$X \rightarrow .$$X$$+Y ,  \$ $

$X \rightarrow .X+Y ,  + $ (this production is added due to $X$ )

$X \rightarrow .Y ,  \$ $

$X \rightarrow .Y ,  + $

$Y \rightarrow .Y*Z ,  + | \$$

$Y \rightarrow .Y*Z ,  *$

$Y \rightarrow .Z ,  + | \$$

$Y \rightarrow .Z ,  *$

$Z \rightarrow .(X) , * $

$Z \rightarrow .(X) ,  + | \$$

$Z \rightarrow .id , + | \$ $

$Z \rightarrow .id , * $

now $X \rightarrow .Y$ have $2$ look aheads $ \$, + $ and $Z \rightarrow .id $ have $3$ look aheads $* , + ,\$ $

3
3

1 Answer

5 votes
5 votes

yes it will have 5 . 

Related questions