search
Log In
9 votes
4.8k views

Consider the grammar given below:

  • $S \rightarrow Aa$
  • $A \rightarrow BD$
  • $B \rightarrow b \mid \epsilon $
  • $D \rightarrow d \mid \epsilon $


Let $a,b,d$ and $\$$ be indexed as follows:$$\begin{array}{|l|l|l|l|} \hline a & b & d & \$ \\ \hline 3 & 2 & 1 & 0 \\ \hline \end{array}$$Compute the FOLLOW set of the non-terminal B and write the index values for the symbols in the FOLLOW set in the descending order.(For example, if the FOLLOW set is $(a,b,d, \$)$ , then the answer should be $3210$)

in Compiler Design
edited by
4.8k views
1
ad 31
1
I wrote 13 :/
0
  first() follow()
 S a,b,d  $
 A b,d,$\epsilon$ a
 B b, $\epsilon$ a,d
 D d, $\epsilon$ a

 

0
how you are getting follow(D) =d ?
0
Corrected. Thanks for correcting me.
0

  follow(D)= follow(A).

0

@Satbir

How you got first of $S?$

1
first(S) = first (A)= first(B) = b , epsilon

Now substitute epsilon in place of B in A-> BD

So first(A) = first(D) = d, epsilon

So this means A can generate b,d, epsilon.

Now if we substitute epsilon in S->Aa then we can get first(S) = a

Note that we are not writing epsilon in first(S) because S can't generate epsilon.

Hence first(S) = {a,b,d}
0
I confused, on that because I thought $'S'$ can generate $\epsilon.$

Now it is clear for me,thanks
0
Same bro

3 Answers

17 votes
 
Best answer
For $\text{Follow(B)} \implies \text{First(D)} = \{ d, \epsilon \}$

Put $\epsilon$ in $II$ production

$\text{Follow (B)} = \text{ Follow (A)} = \{ a\}$

$\text{Follow (B)} = \{ d,a \}$

According to the question writing Follow set in decreasing order:$$\begin{array}{|l|l|} \hline a & d \\ \hline 3 & 1 \\ \hline \end{array}$$Hence $31$ is correct answer

edited by
0

 Here follow of B is {a,d} not {$,a,d}.

1

@Rishav_Bhatt

@Ashwani Kumar 2

Why $\$$ won't come?

 

1
@JEET, $\$$ is in follow of $S$ & no where we have to calculate follow of $S$ while calculating follow of $B$
0

Thanks

8 votes
Follow of B={d,a}

D is right of B so we take terminal first of D that is d if D is € in such case follow of B=follow of A that is a

So answer is ad = 31
2 votes

Answer is: 31

1. Here B is in the right side of the Production Rule:

$A\rightarrow BD$                 $\therefore FOLLOW(B)= FIRST(D)$ 

$FIRST(D)=d$ (Therfore it is in $FOLLOW(B)$)

Finally Putting $D\rightarrow \varepsilon$ in the Production $A\rightarrow BD$   then $FOLLOW(B)=FOLLOW(A)$

$FOLLOW(A)=a$ (From the Production rule $S\rightarrow Aa$)

$\therefore FOLLOW(B)= (d,a)$

As we have to write answer in the Decreasing order of INDEX (a,d) $\rightarrow$ (31)


edited by
Answer:

Related questions

5 votes
2 answers
1
3.6k views
Which one of the following kinds of derivation is used by LR parsers? Leftmost Leftmost in reverse Rightmost Rightmost in reverse
asked Feb 7, 2019 in Compiler Design Arjun 3.6k views
7 votes
3 answers
2
5k views
Consider the augmented grammar given below: $S’ \rightarrow S$ $S \rightarrow \langle L \rangle \mid id$ $L \rightarrow L, S \mid S$ Let $I_0 = \text{CLOSURE} (\{[S’ \rightarrow \cdot S ]\}).$ The number of items in the set $\text{GOTO} (I_0, \langle \: )$ is______
asked Feb 7, 2019 in Compiler Design Arjun 5k views
6 votes
6 answers
3
4k views
Consider the following grammar and the semantic actions to support that inherited type declaration attributes. Let $X_1, X_2, X_3, X_4, X_5$, and $X_6$ be the placeholders for the non-terminals $D, T, L$ or $L_1$ ... $X_1=L, \: X_2=L, \: X_3=L_1, \: X_4 = T$ $X_1=T, \: X_2=L, \: X_3=T, \: X_4 = L_1$
asked Feb 7, 2019 in Compiler Design Arjun 4k views
12 votes
8 answers
4
5.6k views
The following C program is executed on a Unix/Linux system : #include<unistd.h> int main() { int i; for(i=0; i<10; i++) if(i%2 == 0) fork(); return 0; } The total number of child processes created is ________________ .
asked Feb 7, 2019 in Operating System Arjun 5.6k views
...