GATE CSE
First time here? Checkout the FAQ!
x
+4 votes
577 views

Consider a Grammar G as follows :

$S\rightarrow W$

$W \rightarrow ZXY / XY$

$Y\rightarrow c/\epsilon$

$Z\rightarrow a/d$

$X\rightarrow Xb/\epsilon$


Draw the LL(1) parsing table for the given grammar ?


NOTE :- The above grammar is NOT LL(1) .

asked in Compiler Design by Veteran (50.4k points) 22 90 410 | 577 views

1 Answer

+6 votes
Best answer

S→W

W→ZXY / XY

Y→c/ϵ

Z→a/d

X→Xb/ϵ


First(S) = { a, d, b, c, d, ϵ}  , Follow(S) = { $ }

First(W) = { a, d, b, c, d, ϵ} , Follow(W) = { $ }

First(X) = { b, ϵ}                  , Follow(X) = {b, c,$ }

First(Y) = { c, ϵ}                 , Follow(Y) = { $ }

First(Z) = { a, d}                 , Follow(Z) = { b, c, $ }

 


LL(1) Table-


Place A -> B in the first of B in row A.

If  A -> B , and first of A =ϵ or B = ϵ , then place A-> B, in the follow of A.


  a b c d $
S S->W S->W S->W S->W S->W
W W->ZXY W->XY W->XY W->ZXY W->XY
X  

X->Xb

X->$\epsilon$

X->$\epsilon$   X->$\epsilon$
Y     Y->c   Y->$\epsilon$
Z Z->a     Z->d  

 

Because of X-> Xb and X -> ϵ , going in same block, given grammar is not LL(1).

??

answered by Veteran (27k points) 13 48 207
selected by

Very Nice :)

Just a doubt ?

$X\rightarrow Xb$ won't go in $c$ and $ ?

I don't think so..

X-> Xb would go only in the first of (Xb) right ?? And first of Xb = { b } ..right ??

 

Okk !!

I am not sure but just thought that first of {Xb} = first of {X}

And, First of {X} = {b,c,$} ?

First(X) = { b, $\epsilon$ }

Follow(X)={b, c, $ }.
Yes, u r right .
Can you tell why did you put first pproduction S->W in $ too ? I assume it is because when W = ϵ then  production becomes S-> ϵ and goes in Follow(S). Do I understand it correct ?

Amey Umarekar

S→W ::: W→XY::::X→ϵ,Y→ϵ:::::W→ϵ :::::S→ϵ

Follow of S=$

@  saxena0612

Ohh ok, so same goes with W->XY in Follow(W). Thanks !!



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
Top Users Oct 2017
  1. Arjun

    23338 Points

  2. Bikram

    17048 Points

  3. Habibkhan

    7912 Points

  4. srestha

    6228 Points

  5. Debashish Deka

    5438 Points

  6. jothee

    4968 Points

  7. Sachin Mittal 1

    4772 Points

  8. joshi_nitish

    4286 Points

  9. sushmita

    3964 Points

  10. Rishi yadav

    3794 Points


Recent Badges

Popular Question makhdoom ghaya
Popular Question junaid ahmad
Notable Question learner_geek
Notable Question jothee
Popular Question jothee
Notable Question Jeffrey Jose
Notable Question air1ankit
Nice Question jothee
Verified Human shaleen25
Popular Question jothee
27,290 questions
35,142 answers
83,920 comments
33,231 users