GateAI
Lexical Analysis, Parsing and SDT

GATE CSE 2019 · Q19

NAT1 markMedium

Time

Consider the grammar given below: S→AaS \rightarrow Aa A→BDA \rightarrow BD B→b∣ϵB \rightarrow b \mid \epsilon D→d∣ϵD \rightarrow d \mid \epsilon Let a, b, d, and be indexed as follows: 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: _______.

GATE CSE 2019 Q19 diagram

Your answerNumerical answer

Enter a value to check

Solution

Step-by-step verified solution

Official answer: 31

Lexical Analysis, Parsing and SDT

To compute FOLLOW(B)\text{FOLLOW}(B):

  1. From the production A→BDA \rightarrow BD:

    FOLLOW(B) includes (FIRST(D)∖{ϵ})\text{FOLLOW}(B) \text{ includes } (\text{FIRST}(D) \setminus \{\epsilon\})

    Since D→d∣ϵD \rightarrow d \mid \epsilon, FIRST(D)={d,ϵ}\text{FIRST}(D) = \{d, \epsilon\}. Therefore, d∈FOLLOW(B)d \in \text{FOLLOW}(B).

  2. Since ϵ∈FIRST(D)\epsilon \in \text{FIRST}(D), FOLLOW(B)\text{FOLLOW}(B) also includes FOLLOW(A)\text{FOLLOW}(A):

    FOLLOW(B)⊇FOLLOW(A)\text{FOLLOW}(B) \supseteq \text{FOLLOW}(A)
  3. From the production S→AaS \rightarrow Aa:

    FOLLOW(A)={a}\text{FOLLOW}(A) = \{a\}

    Therefore, a∈FOLLOW(B)a \in \text{FOLLOW}(B).

  4. Thus, FOLLOW(B)={a,d}\text{FOLLOW}(B) = \{a, d\}.

  5. Using the given indexing:

    • a→3a \rightarrow 3

    • d→1d \rightarrow 1

Arranging the indices in descending order gives 31.

Try the question first, then check your work.

Think the official key or this write-up is wrong?

Report error or challenge

Examiner trap

The misconception this question tests

This Lexical Analysis, Parsing and SDT previous year question is Q19 of the GATE CSE 2019 paper. Find more GATE CSE PYQs on Lexical Analysis, Parsing and SDT in Compiler Design, or browse all GATE CSE PYQs.

Free diagnostic

Where do you stand for GATE?

Take the 20-minute diagnostic: the 3 topics that cost you the most marks, and a rank range. Or sit 5 related Lexical Analysis, Parsing and SDT PYQs now with no account.

One GATE CSE PYQ every morning

An official question by email at 7 AM IST, with a link to its verified solution. Unsubscribe in one click.

Lexical Analysis, Parsing and SDT in GATE CSE

Lexical Analysis, Parsing and SDT has 14 GATE CSE PYQs across 12 papers from 2011 to 2025. 2 of them are 1-mark NAT questions like this one, and GATE CSE 2019 has 2.

How GATE tests Lexical Analysis, Parsing and SDT

More from GATE CSE 2019

Share this solution

A plain-text card for WhatsApp or Telegram study groups.

GateAI solution cardGATE CSE 2019 · Q19 · NAT

Consider the grammar given below: S → Aa A → BD B → b D → d Let a, b, d, and $ be indexed as follows: 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: …

Topic-wise GATE CS PYQs with verified steps

Independent practice explanation verified by the GateAI team. GATE is conducted by the IITs; question text follows the official paper.