GateAI
Parsing

GATE CSE 2024 Set 2 · Q40

MCQ2 marksMedium

Time

Consider the following context-free grammar where the start symbol is SS and the set of terminals is {a,b,c,d}\{a,b,c,d\}. S→AaAb∣BbBaA→cS∣ϵB→dS∣ϵ\begin{aligned} S &\to AaAb \mid BbBa A &\to cS \mid \epsilon B &\to dS \mid \epsilon \end{aligned} The following is a partially-filled LL(1) parsing table. Which one of the following options represents the CORRECT combination for the numbered cells in the parsing table? Note: In the options, “blank” denotes that the corresponding cell is empty.

GATE CSE 2024 Set 2 Q40 diagram

Select one answerSingle correct

Pick an option to check

Solution

Step-by-step verified solution

Official answer: A) (1) S → AaAb (2) S → BbBa (3) A → (4) B →

Parsing

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

### 1. First Sets

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

  • FIRST(B)={d,ϵ}\text{FIRST}(B) = \{d, \epsilon\}

  • For production S→AaAbS \to AaAb:

    FIRST(AaAb)=(FIRST(A)∖{ϵ})∪FIRST(aAb)={c}∪{a}={a,c}\text{FIRST}(AaAb) = (\text{FIRST}(A) \setminus \{\epsilon\}) \cup \text{FIRST}(aAb) = \{c\} \cup \{a\} = \{a, c\}

    Therefore, S→AaAbS \to AaAb is entered in M[S,a]M[S, a] and M[S,c]M[S, c].

    • Cell (1) is M[S,c]M[S, c], so (1) = S→AaAbS \to AaAb.

  • For production S→BbBaS \to BbBa:

    FIRST(BbBa)=(FIRST(B)∖{ϵ})∪FIRST(bBa)={d}∪{b}={b,d}\text{FIRST}(BbBa) = (\text{FIRST}(B) \setminus \{\epsilon\}) \cup \text{FIRST}(bBa) = \{d\} \cup \{b\} = \{b, d\}

    Therefore, S→BbBaS \to BbBa is entered in M[S,b]M[S, b] and M[S,d]M[S, d].

    • Cell (2) is M[S,d]M[S, d], so (2) = S→BbBaS \to BbBa.

### 2. Follow Sets for ϵ\epsilon-productions

  • For production A→ϵA \to \epsilon, the entry is placed in M[A,t]M[A, t] for every t∈FOLLOW(A)t \in \text{FOLLOW}(A). From S→AaAbS \to AaAb, AA appears before aa and also before bb. Thus, {a,b}⊆FOLLOW(A)\{a, b\} \subseteq \text{FOLLOW}(A). Therefore, A→ϵA \to \epsilon is placed in M[A,a]M[A, a] and M[A,b]M[A, b].

    • Cell (3) is M[A,b]M[A, b], so (3) = A→ϵA \to \epsilon.

  • For production B→ϵB \to \epsilon, the entry is placed in M[B,t]M[B, t] for every t∈FOLLOW(B)t \in \text{FOLLOW}(B). From S→BbBaS \to BbBa, BB appears before bb and also before aa. Thus, {a,b}⊆FOLLOW(B)\{a, b\} \subseteq \text{FOLLOW}(B). Therefore, B→ϵB \to \epsilon is placed in M[B,b]M[B, b] and M[B,a]M[B, a].

    • Cell (4) is M[B,a]M[B, a], so (4) = B→ϵB \to \epsilon.

Thus, the correct combination is given by (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 Parsing previous year question is Q40 of the GATE CSE 2024 Set 2 paper. Find more GATE CSE PYQs on Parsing 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 Parsing 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.

Parsing in GATE CSE

Parsing has 23 GATE CSE PYQs across 16 papers from 2012 to 2026. 11 of them are 2-mark MCQs like this one, and GATE CSE 2024 Set 2 has 2.

How GATE tests Parsing

More from GATE CSE 2024 Set 2

Share this solution

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

GateAI solution cardGATE CSE 2024 Set 2 · Q40 · MCQ

Consider the following context-free grammar where the start symbol is S and the set of terminals is {a,b,c,d}. S &→ AaAb BbBa A &→ cS B &→ dS The following is a partially-filled LL(1) parsing table. Which one of the following options represents the CORRECT combination for the numbered cells in the parsing table? Note: In the options, “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.