search
Log In
0 votes
297 views

in Compiler Design
edited by
297 views
0
Getting 4 but given ans is 2
0

how did u gate 4,....

1. one for s row a column 

2. s row b column..

2...

0
only (S,a) and (S,b) will have 2 entries. So 2 is ryt.
0
Got it but 2 entries would be under (A,a) and (A,b)
0
Under (S,a) entry : S$\rightarrow$aAbB, S$\rightarrow$ϵ

Under (S,b) entry : S$\rightarrow$bAaB, S$\rightarrow$ϵ

Under (A,a) and (A,b) : A$\rightarrow$S
0

no ..under (A,a) and(A,b)...we would get...A->S   First of S(a,b)

similarly   under (B,a) and (B,b)....B->S

1 Answer

1 vote

$First (S) = First(A) = First(B)= {\{a, b, \epsilon}\} \\ Follow (S)= {\{a, b, \$} \}$

$Follow (A)= {\{a, b} \}$

$Follow (B)= {\{a, b, \$} \}$

LL(1) Parse Table:

  $a$ $b$ $
$S$

$S\rightarrow aAbB$

$S\rightarrow \epsilon$

$S\rightarrow bAaB$

$S\rightarrow \epsilon$

$S\rightarrow \epsilon$
$A$ $A\rightarrow S$ $A\rightarrow S$  
$B$ $B\rightarrow S$ $B\rightarrow S$ $B\rightarrow S$

2 multiple entries

Hence 2 is the correct answer


edited by
0
will you please write its first and follow table?
0
Done
0
now, why not there is entry for A--->ϵ under T[A,a], T[A,b]

similarly, why not there is entry for B--->ϵ under T[B,a], T[B,b] , T[B,$]
0
Because there is no such production for A and B present in grammar
0
but indirectly A is driving epsilon
1
Yes, it is driving but we didn't add it into the table, we add only those entries present in grammar.

See LL(1) is a predictive parser, on the basis of current input symbol it decides which grammar production it will select.

Suppose at any instant when next input symbol is 'a' which is in first of A then production A->S is selected by parser

LL(1) table contains only productions present in grammar
0
thanks !

Related questions

1 vote
0 answers
1
511 views
Why ε is not shown in First(S). First(s) does contain ε . And please help me figure out which grammar is this? According to me it is NOT LL(1) (since it is left factored), NOT LR(0) (Since the Item 0 has a R-R conflict), NOT SLR(1) (The item 0 has a RR conflict since Follow(X) = Follow(Y) = {a,b} correct me If i'm wrong
asked Nov 23, 2018 in Compiler Design Hopealways 511 views
1 vote
0 answers
2
2 votes
0 answers
3
941 views
Consider the following grammar which is not LL(1) because LL(1) table contain multiple entry for same production. The number of entries have multiple productions in LL(1) table are ________.
asked Aug 19, 2018 in Compiler Design Mizuki 941 views
0 votes
0 answers
4
105 views
Let G be a grammar with the following productions: If LR(1) parser is used to construct the DFA using the above productions, then how many look-a-heads are present for an item T → .T * F in the initial state ________.
asked Jun 12, 2018 in Compiler Design syncronizing 105 views
...