GateAI
Lexical Analysis, Parsing and SDT

GATE CSE 2021 Set 1 · Q31

MCQ2 marksMedium

Time

Consider the following context-free grammar where the set of terminals is {a,b,c,d,f}\{a, b, c, d, f\}. S→daT∣RfT→aS∣baT∣ϵR→caTR∣ϵ\begin{aligned} S &\to d a T \mid R f \\ T &\to a S \mid b a T \mid \epsilon \\ R &\to c a T R \mid \epsilon \end{aligned} The following is a partially-filled LL(1) parsing table. Which one of the following choices represents the correct combination for the numbered cells in the parsing table (“blank” denotes that the corresponding cell is empty)?

GATE CSE 2021 Set 1 Q31 diagram

Select one answerSingle correct

Pick an option to check

Solution

Step-by-step verified solution

Official answer: A) ① S → R f ② S → R f ③ T → ④ T →

Lexical Analysis, Parsing and SDT

To fill the LL(1) parsing table, we compute the FIRST\text{FIRST} and FOLLOW\text{FOLLOW} sets for each non-terminal.

### 1. FIRST Sets:

  • FIRST(R)={c,ϵ}\text{FIRST}(R) = \{c, \epsilon\}

  • FIRST(T)={a,b,ϵ}\text{FIRST}(T) = \{a, b, \epsilon\}

  • FIRST(S)={d}∪FIRST(Rf)={d}∪{c,f}={c,d,f}\text{FIRST}(S) = \{d\} \cup \text{FIRST}(R f) = \{d\} \cup \{c, f\} = \{c, d, f\}

### 2. FOLLOW Sets:

  • Since SS is the start symbol, \\ \in FOLLOW\text{FOLLOW}(S)$.

  • From T→aST \to a S, FOLLOW(S)\text{FOLLOW}(S) contains FOLLOW(T)\text{FOLLOW}(T).

  • From S→RfS \to R f, FOLLOW(R)={f}\text{FOLLOW}(R) = \{f\}.

  • From R→caTRR \to c a T R, FOLLOW(T)\text{FOLLOW}(T) contains (FIRST(R)∖{ϵ})∪FOLLOW(R)={c}∪{f}={c,f}(\text{FIRST}(R) \setminus \{\epsilon\}) \cup \text{FOLLOW}(R) = \{c\} \cup \{f\} = \{c, f\}.

  • From S→daTS \to d a T, FOLLOW(T)\text{FOLLOW}(T) contains FOLLOW(S)\text{FOLLOW}(S). Thus, \\ \in FOLLOW\text{FOLLOW}(T)$.

  • Therefore, \text{FOLLOW}(T) = \{c, f, \\}and and FOLLOW\text{FOLLOW}(S) = \{c, f, \$\}.

### 3. Parsing Table Entries:

  • For production S→RfS \to R f:

    FIRST(Rf)={c,f}\text{FIRST}(R f) = \{c, f\}

    This production is placed in M[S,c]M[S, c] (cell ①) and M[S,f]M[S, f] (cell ②).

    • Cell ① = S→RfS \to R f

    • Cell ② = S→RfS \to R f

  • For production T→ϵT \to \epsilon:

    FOLLOW(T)={c,f,$}\text{FOLLOW}(T) = \{c, f, \$\}

    This production is placed in M[T,c]M[T, c] (cell ③), M[T,f]M[T, f], and M[T, \]$ (cell ④).

    • Cell ③ = T→ϵT \to \epsilon

    • Cell ④ = T→ϵT \to \epsilon

Thus, the correct combination is given by Option (A).

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 Q31 of the GATE CSE 2021 Set 1 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 2-mark MCQs like this one, and it is the only one in GATE CSE 2021 Set 1.

How GATE tests Lexical Analysis, Parsing and SDT

More from GATE CSE 2021 Set 1

Share this solution

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

GateAI solution cardGATE CSE 2021 Set 1 · Q31 · MCQ

Consider the following context-free grammar where the set of terminals is {a, b, c, d, f}. S &→ d a T R f T &→ a S b a T R &→ c a T R The following is a partially-filled LL(1) parsing table. Which one of the following choices represents the correct combination for the numbered cells in the parsing table (“blank” denotes that the corresponding cell is empty)?

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.