Skip to main content

GATE CSE 2025Compiler Design › Grammars & ParsingVerified

GATE CSE 2025 PYQ: Which of the following statement(s) is/are TRUE while computing First ⁡ \operatorname{First} First and…

Which of the following statement(s) is/are TRUE while computing First⁡\operatorname{First} and Follow⁡\operatorname{Follow} during top down parsing by a compiler?

  1. A
    For a production A→ϵ,ϵA \rightarrow \epsilon, \epsilon will be added to First⁡(A)\operatorname{First}(A).
    Correct answer
  2. B
    If there is any input right end marker, it will be added to First(S)\text{First(S)}, where SS is the start symbol.
  3. C
    For a production A→ϵ,ϵA \rightarrow \epsilon, \epsilon will be added to Follow (A)\text{(A)}.
  4. D
    If there is any input right end marker, it will be added to Follow⁡(S)\operatorname{Follow}(S), where S\text{S} is the start symbol.
    Correct answer

Answer

(A, D) For a production A → ϵ , ϵ A \rightarrow \epsilon, \epsilon A → ϵ , ϵ will be added to First ⁡ ( A ) \operatorname{First}(A) First ( A ) .; If there is any input right end marker, it will be added to Follow ⁡ ( S ) \operatorname{Follow}(S) Follow ( S ) , where S \text{S} S is the start symbol.

Approach

Use the standard definitions of FIRST and FOLLOW: FIRST(A) contains terminals that can begin strings derived from A and also contains ε if A derives ε. FOLLOW(A) contains terminals and the end-of-input marker that can appear immediately after A in some sentential form. ε is never added to any FOLLOW set.

The correct statements are A and D. A holds because ε is placed in FIRST(A) when A → ε. D holds because the end-of-input marker is placed in FOLLOW(S) for the start symbol S. B and C are false because the end marker does not go into FIRST and ε does not go into FOLLOW.

Reviewed by GateIQ Editorial Team: IIT & IISc Alumni.