Similar questions 3 more →
Parsing & Syntax Analysis

Answer & solution
Official answer: 31
Step through it (13 steps)
Method: use the rule for a nonterminal followed by a possibly nullable suffix.
1. FOLLOW(B) contains terminals that can appear immediately after B in a sentential form, not the terminals that B itself derives. In A→BD, the suffix following B is D.
2. FIRST(D)={d,ε}. Add its non-epsilon terminal d to FOLLOW(B), because D may produce d immediately after B.
3. D can also disappear via D→ε. In that case whatever follows A also follows B. From S→Aa, the terminal a follows A, so FOLLOW(A)={a}; add a to FOLLOW(B).
4. There are no other occurrences contributing more symbols. In particular, $ follows the start symbol S, but the required terminal a after A prevents $ from propagating to A or B. The symbol b is in FIRST(B), not FOLLOW(B), and ε is never a FOLLOW-set member.
5. Thus FOLLOW(B)={a,d}. Their indices are 3 and 1, already in descending order, so concatenate them as 31.
Result: 31. The language generated from S is {a,ba,da,bda}, which also illustrates that a B occurrence is followed by d or a.