The Gateway to Computer Science Excellence
0 votes
91 views
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 by Boss (13.8k points)
reopened by | 91 views
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
but hemanth it is asking for particular items right? so it will still different for both the items .isnt so?
0

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

0
It is a duplicate question

Answer is 5

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

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

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

+1
2 +3 = 5

for X->.Y +/\$

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

Are you sure about the answer?
0

@VikramRB Yeah! I am sure.

 

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

here lookaheads are $,+, *

what other two?
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

@adarsh_1997 here look ahead will be only 3

$,*,+

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

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

$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 $* , + ,\$ $

1 Answer

+3 votes

yes it will have 5 . 

by Active (3.7k points)

Related questions

Quick search syntax
tags tag:apple
author user:martin
title title:apple
content content:apple
exclude -tag:apple
force match +apple
views views:100
score score:10
answers answers:2
is accepted isaccepted:true
is closed isclosed:true
50,645 questions
56,563 answers
195,731 comments
101,651 users