in Compiler Design retagged by
2,211 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

4 Comments

@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