The Gateway to Computer Science Excellence
+7 votes

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 by Veteran (430k points)
edited by | 2.7k views
ad 31
I wrote 13 :/
  first() follow()
 S a,b,d  $
 A b,d,$\epsilon$ a
 B b, $\epsilon$ a,d
 D d, $\epsilon$ a


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

  follow(D)= follow(A).

3 Answers

+13 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
by Boss (16.3k points)
edited by

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



@Ashwani Kumar 2

Why $\$$ won't come?


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


+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
by Loyal (5.3k points)
+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)

by Junior (841 points)
edited by

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,741 questions
57,253 answers
104,703 users