Question

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∣BbBaS \rightarrow AaAb \mid BbBa
A→cS∣ϵA \rightarrow cS \mid \epsilon
B→dS∣ϵB \rightarrow dS \mid \epsilon

The following is a partially-filled LL(1) parsing table.

aabbccdd$\$
SSS→AaAbS \rightarrow AaAbS→BbBaS \rightarrow BbBa(1)(2)
AAA→ϵA \rightarrow \epsilon(3)A→cSA \rightarrow cS
BB(4)B→ϵB \rightarrow \epsilonB→dSB \rightarrow dS

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.

Choose one option
Official answer and solution
Official answer
A
From
Official GATE 2024 answer key

Solution

Compute FIRST(AaAb)\text{FIRST}(AaAb), FIRST(BbBa)\text{FIRST}(BbBa), FOLLOW(A)\text{FOLLOW}(A), and FOLLOW(B)\text{FOLLOW}(B).

  1. FIRST sets for productions of SS:
    • Since FIRST(A)={c,ϵ}\text{FIRST}(A) = \{c, \epsilon\}, we have FIRST(AaAb)=(FIRST(A)−{ϵ})∪{a}={c,a}\text{FIRST}(AaAb) = (\text{FIRST}(A) - \{\epsilon\}) \cup \{a\} = \{c, a\}. Therefore, cell (1) (row SS, column cc) contains S→AaAbS \rightarrow AaAb.
    • Since FIRST(B)={d,ϵ}\text{FIRST}(B) = \{d, \epsilon\}, we have FIRST(BbBa)=(FIRST(B)−{ϵ})∪{b}={d,b}\text{FIRST}(BbBa) = (\text{FIRST}(B) - \{\epsilon\}) \cup \{b\} = \{d, b\}. Therefore, cell (2) (row SS, column dd) contains S→BbBaS \rightarrow BbBa.
  2. FOLLOW sets for ϵ\epsilon-productions of AA and BB:
    • In S→AaAbS \rightarrow AaAb, the first AA is followed by terminal aa and the second AA is followed by terminal bb, so FOLLOW(A)={a,b}\text{FOLLOW}(A) = \{a, b\}. Since A→ϵA \rightarrow \epsilon, cell (3) (row AA, column bb) contains A→ϵA \rightarrow \epsilon.
    • In S→BbBaS \rightarrow BbBa, the first BB is followed by terminal bb and the second BB is followed by terminal aa, so FOLLOW(B)={a,b}\text{FOLLOW}(B) = \{a, b\}. Since B→ϵB \rightarrow \epsilon, cell (4) (row BB, column aa) contains B→ϵB \rightarrow \epsilon.
Final answer

Option (A)

The answer is the one in the official GATE answer key. The solution is this site's own explanation.

Source

Paper
GATE 2024 Computer Science and Information Technology - Set 2 (CS2)
Question
40 of 65
Section
Computer Science and Information Technology

Report an error in this question

GATE questions are the work of the organising institutes. This site is independent and is not affiliated with them.