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?
- A.
(1) π β π π (2) π β π (3) π β πππ
- B.
(1) π β ππ (2) π β π (3) π β πππ
- C.
(1) π β ππ (2) π β ππ (3) π βΒ ππ
- 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.