Consider the following grammar 𝐺, with 𝑆 as the start symbol. The grammar 𝐺…

2024

Consider the following grammar 𝐺, with 𝑆 as the start symbol. The grammar 𝐺 has three incomplete productions denoted by (1), (2), and (3).

Β  Β  Β  Β  Β  Β  Β  Β  Β  Β  Β  Β  Β  𝑆 β†’ π‘‘π‘Žπ‘‡ | (1)

                          𝑇 β†’ π‘Žπ‘† | 𝑏𝑇 | (2)

Β  Β  Β  Β  Β  Β  Β  Β  Β  Β  Β  Β  Β  𝑅 β†’ (3) | πœ–

The set of terminals is {π‘Ž, 𝑏, 𝑐, 𝑑, 𝑓}. The FIRST and FOLLOW sets of the different non-terminals are as follows

Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β FIRST(𝑆) = {𝑐, 𝑑, 𝑓}, FIRST(𝑇) = {π‘Ž, 𝑏, πœ–}, FIRST(𝑅) = {𝑐, πœ–}

Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β  FOLLOW(𝑆) = FOLLOW(𝑇) = {𝑐, 𝑓, $}, FOLLOW(𝑅) = {𝑓}

Which one of the following options CORRECTLY fills in the incomplete productions?

  1. A.

    (1) 𝑆 β†’ 𝑅𝑓 (2) 𝑇 β†’ πœ– (3) 𝑅 β†’ 𝑐𝑇𝑅

  2. B.

    (1) 𝑆 β†’ 𝑓𝑅 (2) 𝑇 β†’ πœ– (3) 𝑅 β†’ 𝑐𝑇𝑅

  3. C.

    (1) 𝑆 β†’ 𝑓𝑅 (2) 𝑇 β†’ 𝑐𝑇 (3) 𝑅 → 𝑐𝑅

  4. D.

    (1) 𝑆 β†’ 𝑅𝑓 (2) 𝑇 β†’ 𝑐𝑇 (3) 𝑅 → 𝑐𝑅

Attempted by 126 students.

Show answer & explanation

Correct answer: A

Final filled productions:

  • S β†’ R f

  • T β†’ Ξ΅

  • R β†’ c T R

Reasoning:

  • S: The grammar already provides S β†’ d a T which covers starting symbol d. To obtain the remaining FIRST symbols c and f, using S β†’ R f works because FIRST(R) = {c, Ξ΅}. If R derives a string starting with c then S can start with c; if R β†’ Ξ΅ then S starts with f. Together with the existing d production this yields FIRST(S) = {c, d, f}.

  • T: The productions T β†’ a S and T β†’ b T already give a and b in FIRST(T). Adding T β†’ Ξ΅ is necessary so that FIRST(T) = {a, b, Ξ΅} matches the given set.

  • R: With R β†’ c T R and R β†’ Ξ΅ available, FIRST(R) = {c, Ξ΅} as required: the c production provides c, and the Ξ΅ alternative provides Ξ΅.

Why other forms fail:

  • Placing f at the start of the S production (for example S β†’ f R) prevents S from starting with c, so FIRST(S) would miss c and not match the given FIRST(S).

  • Using a production like T β†’ c T would introduce c into FIRST(T), which contradicts the given FIRST(T) = {a, b, Ξ΅}.

  • Defining R without an Ξ΅ alternative would remove Ξ΅ from FIRST(R), contradicting the given FIRST(R) = {c, Ξ΅}.

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

Explore the full course: Gate Guidance By Sanchit Sir