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 correct — ConceptLet T be the terminal alphabet. FIRST(γ) ∩ T records terminal symbols that can begin strings derived from γ; ε is added separately when γ is nullable.…
- A.
Both statements S₁ and S₂ are incorrect
- B.
S₁ is incorrect and S₂ is correct
- C.
S₁ is correct and S₂ is incorrect
- 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
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.
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.
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