Which statement(s) is/are correct for a non-recursive predictive parser? Let T…

2013

Which statement(s) is/are correct for a non-recursive predictive parser?

Let T denote the terminal alphabet; ε and the input end marker $ are handled by their separate rules.

S₁: FIRST(α) ∩ T = { t ∈ T | α ⇒* tβ for some string β }

S₂: FOLLOW(X) ∩ T = { a ∈ T | S ⇒* γXaβ for some strings γ and β }

Answer: D. Both statements S₁ and S₂ are correctConceptLet T be the terminal alphabet. FIRST(γ) ∩ T records terminal symbols that can begin strings derived from γ; ε is added separately when γ is nullable.…

  1. A.

    Both statements S₁ and S₂ are incorrect

  2. B.

    S₁ is incorrect and S₂ is correct

  3. C.

    S₁ is correct and S₂ is incorrect

  4. D.

    Both statements S₁ and S₂ are correct

Attempted by 134 students.

Show answer & explanation

Correct answer: D

Concept

Let T be the terminal alphabet. FIRST(γ) ∩ T records terminal symbols that can begin strings derived from γ; ε is added separately when γ is nullable.

FOLLOW(X) ∩ T records terminal symbols that can appear immediately after X in a sentential form; the end marker $ is added separately to the FOLLOW set of the start symbol.

Application

  1. In S₁, the witness α ⇒* tβ puts terminal t at the beginning of a string derived from α. This is exactly the condition for t ∈ FIRST(α) ∩ T.

  2. In S₂, the witness S ⇒* γXaβ puts terminal a immediately after X in a sentential form derived from S. This is exactly the condition for a ∈ FOLLOW(X) ∩ T.

  3. Because both left-hand sides are explicitly intersected with T, the separate ε and $ cases do not affect either terminal-only equality.

Cross-check and contrast

  • “Both statements are incorrect” treats the separate ε and $ additions as counterexamples to valid terminal-membership clauses.

  • “S₁ is incorrect and S₂ is correct” applies the special-symbol caveat only to FIRST even though FOLLOW also has a separate $ rule.

  • “S₁ is correct and S₂ is incorrect” applies the special-symbol caveat only to FOLLOW even though FIRST also has a separate ε rule.

  • “Both statements are correct” reads t and a as terminal witnesses in their respective derivations, which matches the two displayed clauses.

Therefore, both statements S₁ and S₂ are correct.

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

Explore the full course: Mppsc Assistant Professor Computer Science Paper 2

Loading lesson…