Linked answer questions

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. ϵ\epsilon is the empty string, $\$ indicates end of input, and ∣| separates alternate right hand sides of productions.

S→aAbB∣bAaB∣ϵS \to aAbB \mid bAaB \mid \epsilon
A→SA \to S
B→SB \to S
Non-terminal aa bb $\$
SS E1 E2 S→ϵS \to \epsilon
AA A→SA \to S A→SA \to S error
BB B→SB \to S B→SB \to S E3

Shared with question 52.

Question

The appropriate entries for E1, E2, and E3 are

Choose one option
Official answer and solution
Official answer
C
From
Official GATE 2012 answer key

Solution

Populate LL(1) parsing table cells for non-terminals S on a (E1), S on b (E2), and B on end-of-input (E3).

  1. LL(1) table construction rules:
  • For X→αX \to \alpha, add X→αX \to \alpha to M[X,t]M[X, t] for all t∈FIRST(α)t \in \text{FIRST}(\alpha).
  • If ϵ∈FIRST(α)\epsilon \in \text{FIRST}(\alpha), add X→αX \to \alpha to M[X,t]M[X, t] for all t∈FOLLOW(X)t \in \text{FOLLOW}(X).
  1. For cell M[S,a]M[S, a] (entry E1):
  • S→aAbBS \to aAbB has a∈FIRST(aAbB)a \in \text{FIRST}(aAbB), so add S→aAbBS \to aAbB.
  • S→ϵS \to \epsilon has ϵ∈FIRST(ϵ)\epsilon \in \text{FIRST}(\epsilon). Since a∈FOLLOW(S)a \in \text{FOLLOW}(S), also add S→ϵS \to \epsilon.
  • Thus, E1 contains: S→aAbB,S→ϵS \to aAbB, S \to \epsilon.
  1. For cell M[S,b]M[S, b] (entry E2):
  • S→bAaBS \to bAaB has b∈FIRST(bAaB)b \in \text{FIRST}(bAaB), so add S→bAaBS \to bAaB.
  • S→ϵS \to \epsilon has b∈FOLLOW(S)b \in \text{FOLLOW}(S), so add S→ϵS \to \epsilon.
  • Thus, E2 contains: S→bAaB,S→ϵS \to bAaB, S \to \epsilon.
  1. For cell M[B,$ ]M[B, \text{\$}\,] (entry E3):
  • B→SB \to S has FIRST(S)={a,b,ϵ}\text{FIRST}(S) = \{a, b, \epsilon\}.
  • Because ϵ∈FIRST(S)\epsilon \in \text{FIRST}(S), we look at FOLLOW(B)\text{FOLLOW}(B), which contains $\text{\$}.
  • Therefore, add B→SB \to S to M[B,$ ]M[B, \text{\$}\,].
  • Thus, E3 contains: B→SB \to S.
  1. Combining E1, E2, E3 matches option (C).
Final answer

C

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

Source

Paper
GATE 2012 Computer Science and Information Technology (CS)
Question
53 of 65, printed as CS Q.53
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.