The Gateway to Computer Science Excellence
0 votes
208 views

in Compiler Design by Active (1.1k points)
edited by | 208 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

by Boss (15.5k points)
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

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,666 questions
56,170 answers
193,841 comments
94,047 users