Consider the following context-free grammar where the start symbol is 𝑆 and…

2024

Consider the following context-free grammar where the start symbol is 𝑆 and the set of terminals is {π‘Ž,𝑏,𝑐,𝑑}.

                𝑆 β†’ π΄π‘Žπ΄π‘ | π΅π‘π΅π‘Ž

                𝐴 β†’ 𝑐𝑆 | πœ–

                𝐡 β†’ 𝑑𝑆 | πœ–

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

a

b

c

d

$

S

𝑆 β†’ π΄π‘Žπ΄π‘

𝑆 β†’ π΅π‘π΅π‘Ž

(1)

(2)

A

 𝐴 β†’Β πœ–

(3)

𝐴 → 𝑐𝑆

B

(4)

π΅Β β†’Β πœ–

𝐡 → 𝑑𝑆

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.

  1. A.

    (1) 𝑆 β†’ π΄π‘Žπ΄π‘ (2) 𝑆 β†’ π΅π‘π΅π‘Ž (3) 𝐴 β†’ πœ– (4) 𝐡 β†’ πœ–

  2. B.

    (1) 𝑆 β†’ π΅π‘π΅π‘Ž (2) 𝑆 β†’ π΄π‘Žπ΄π‘ (3) 𝐴 β†’ πœ– (4) 𝐡 β†’ πœ–

  3. C.

    (1) 𝑆 β†’ π΄π‘Žπ΄π‘ (2) 𝑆 β†’ π΅π‘π΅π‘Ž (3) blank (4) blank

  4. D.

    (1) 𝑆 β†’ π΅π‘π΅π‘Ž (2) 𝑆 β†’ π΄π‘Žπ΄π‘ (3) blank (4) blank

Attempted by 96 students.

Show answer & explanation

Correct answer: A

Key idea: compute FIRST and FOLLOW to fill the LL(1) table.

FIRST and FOLLOW sets (relevant parts):

  • FIRST(A) = {c, Ξ΅}; FIRST(B) = {d, Ξ΅}.

  • For S β†’ A a A b, FIRST contains {c} from A and also 'a' because A can be Ξ΅ β†’ so this production is predicted on lookahead 'c' or 'a'.

  • For S β†’ B b B a, FIRST contains {d} from B and also 'b' because B can be Ξ΅ β†’ so this production is predicted on lookahead 'd' or 'b'.

  • FOLLOW(A) = {a, b} and FOLLOW(B) = {a, b}, so A β†’ Ξ΅ and B β†’ Ξ΅ appear in the table cells for those terminals.

Therefore the correct entries for the numbered cells are:

  • (1) S β†’ A a A b

  • (2) S β†’ B b B a

  • (3) A β†’ Ξ΅

  • (4) B β†’ Ξ΅

This matches the option that assigns those productions to the numbered cells.

A video solution is available for this question β€” log in and enroll to watch it.

Explore the full course: Gate Guidance By Sanchit Sir