The GATE Grind

GATE 2025 CS (CS1) – Question 46

Compiler Design · Parsing and Syntax Analysis · 2 marks · Multiple select

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

  1. For a production $A \rightarrow \epsilon$, $\epsilon$ will be added to $First(A)$.
  2. If there is any input right end marker, it will be added to $First(S)$, where $S$ is the start symbol.
  3. For a production $A \rightarrow \epsilon$, $\epsilon$ will be added to $Follow(A)$.
  4. If there is any input right end marker, it will be added to $Follow(S)$, where $S$ is the start symbol.

Practise this question in The GATE Grind →

Show answer and explanation

Correct answer: (A) For a production $A \rightarrow \epsilon$, $\epsilon$ will be added to $First(A)$.; (D) If there is any input right end marker, it will be added to $Follow(S)$, where $S$ is the start symbol.

Explanation

**1. Distinguish FIRST from FOLLOW.** FIRST(A) describes how strings derived from A can begin, including ε when A can derive the empty string. FOLLOW(A) contains terminal symbols that may appear immediately after A in a sentential form.

**2. Check the epsilon statements.** A production A → ε directly adds ε to FIRST(A), so A is true. It does not place ε in FOLLOW(A); ε is not an input terminal that can follow anything, so C is false.

**3. Place the input end marker.** The end marker belongs to FOLLOW(S) for the start symbol because a completed start-symbol derivation can be followed by the end of input. It is not put in FIRST(S). Thus D is true and B false. **Answers: A,D.**

More Parsing and Syntax Analysis questions

All Parsing and Syntax Analysis questions →