Am I correct?

The Gateway to Computer Science Excellence

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.

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.

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?

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

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

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

and {\$,+} for X→.Y

+1

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

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

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

- 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,645 questions

56,563 answers

195,731 comments

101,651 users