GateAI
Parsing

GATE CSE 2012 · Q52

MCQ2 marksMedium

Time

Statement for Linked Answer Questions 52 and 53

For the grammar below, a partial LL(1) parsing table is also presented along with the grammar. Entries that need to be filled are indicated as E1, E2, and E3. ε\varepsilon is the empty string, $\$ indicates end of input, and ∣\mid separates alternate right hand sides of productions. S→aAbB∣bAaB∣εS \rightarrow aAbB \mid bAaB \mid \varepsilon A→SA \rightarrow S B→SB \rightarrow S The FIRST and FOLLOW sets for the non-terminals A and B are

GATE CSE 2012 Q52 diagram

Select one answerSingle correct

Pick an option to check

Solution

Step-by-step verified solution

Official answer: A) FIRST(A) = {a, b, } = FIRST(B) FOLLOW(A) = {a, b} FOLLOW(B) = {a, b, \$}

Parsing

To compute FIRST\text{FIRST} and FOLLOW\text{FOLLOW} sets:

  1. FIRST Sets:

    • From S→aAbB∣bAaB∣εS \rightarrow aAbB \mid bAaB \mid \varepsilon, we have FIRST(S)={a,b,ε}\text{FIRST}(S) = \{a, b, \varepsilon\}.

    • From A→SA \rightarrow S, FIRST(A)=FIRST(S)={a,b,ε}\text{FIRST}(A) = \text{FIRST}(S) = \{a, b, \varepsilon\}.

    • From B→SB \rightarrow S, FIRST(B)=FIRST(S)={a,b,ε}\text{FIRST}(B) = \text{FIRST}(S) = \{a, b, \varepsilon\}.

  2. FOLLOW Sets:

    • Start symbol is SS, so \\in FOLLOW\text{FOLLOW}(S)$.

    • In S→aAbBS \rightarrow aAbB, after AA is bBbB, so FOLLOW(A)\text{FOLLOW}(A) contains FIRST(bB)={b}\text{FIRST}(bB) = \{b\}.

    • In S→bAaBS \rightarrow bAaB, after AA is aBaB, so FOLLOW(A)\text{FOLLOW}(A) contains FIRST(aB)={a}\text{FIRST}(aB) = \{a\}.

    • Thus, FOLLOW(A)={a,b}\text{FOLLOW}(A) = \{a, b\}.

    • In S→aAbBS \rightarrow aAbB and S→bAaBS \rightarrow bAaB, BB is the last symbol, so FOLLOW(B)\text{FOLLOW}(B) contains FOLLOW(S)\text{FOLLOW}(S).

    • Since A→SA \rightarrow S and B→SB \rightarrow S, FOLLOW(S)\text{FOLLOW}(S) contains both FOLLOW(A)\text{FOLLOW}(A) and FOLLOW(B)\text{FOLLOW}(B).

    • Thus, \text{FOLLOW}(S) = \{\\} \cup FOLLOW\text{FOLLOW}(A) \cup FOLLOW\text{FOLLOW}(B) = \{a, b, \$\},whichgives, which gives FOLLOW\text{FOLLOW}(B) = \{a, b, \$\}.

Therefore, FIRST(A)={a,b,ε}=FIRST(B)\text{FIRST}(A) = \{a, b, \varepsilon\} = \text{FIRST}(B), FOLLOW(A)={a,b}\text{FOLLOW}(A) = \{a, b\}, and \text{FOLLOW}(B) = \{a, b, \\}$, matching (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 Q52 of the GATE CSE 2012 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 2012 has 2.

How GATE tests Parsing

More from GATE CSE 2012

Share this solution

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

GateAI solution cardGATE CSE 2012 · Q52 · MCQ

Statement for Linked Answer Questions 52 and 53: For the grammar below, a partial LL(1) parsing table is also presented along with the grammar. Entries that need to be filled are indicated as E1, E2, and E3. is the empty string, \$ indicates end of input, and separates alternate right hand sides of productions. S → aAbB bAaB A → S B → S The FIRST and FOLLOW sets for the non-terminals A and B are

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.