Consider the grammar given below: S → Aa A → BD B → b | ϵ D → d | ϵ Let a, b,…

2019

Consider the grammar given below:

S → Aa

A → BD

B → b | ϵ

D → d | ϵ

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) 

Answer: ________.

Attempted by 140 students.

Show answer & explanation

Correct answer: 31

Key steps to compute FOLLOW(B):

  • B appears in the production A → B D, so include FIRST(D) \u2014 that is {d, ε}.

  • Add FIRST(D) \u2209 ε, i.e. {d}, to FOLLOW(B).

  • Since D can derive ε, also add FOLLOW(A) to FOLLOW(B).

  • A appears in S → A a, so FOLLOW(A) contains the terminal a. Therefore FOLLOW(A) = {a}.

  • Combine results: FOLLOW(B) = {d} ∪ {a} = {a, d}.

Using the given indexes (a = 3, d = 1), list them in descending order to get 31. Final answer: 31.

A video solution is available for this question — log in and enroll to watch it.

Explore the full course: Gate Guidance By Sanchit Sir