GATE / CS ARCHIVE

GATE CSE 2025 SET 1 / QUESTION 46

Distinguishing FIRST from FOLLOW

Compiler Design · Parsing & Syntax Analysis · Full GATE CSE 2025 Set 1 paper

GATE 2025 Set 1, Q46 2 marks · MSQ
Report issue

Parsing & Syntax Analysis

Question 46, GATE 2025: While computing FIRST and FOLLOW for top-down parsing, select true statements: A A→ε adds ε to FIRST(A); B the input end marker is added to FIRST(S), where S is the start symbol; C A→ε adds ε to FOLLOW(A); D the end marker is added to FOLLOW(S).
Tap to enlarge
Select all that apply
Answer & solution

Official answer: A, D

Approach: Keep separate what a nonterminal can begin with and what can appear immediately after it.
FIRST(A) contains terminals that can start a string derived from A, and includes ε when A can derive the empty string. Therefore the production A→ε makes A true.
FOLLOW(A) contains terminals, or the designated end marker, that may occur immediately after A in a sentential form or completed parse. ε is not an input symbol and never belongs in FOLLOW merely because A is nullable, so C is false. Nullability instead causes FOLLOW information to propagate through nullable suffixes.
The start symbol represents an entire accepted input, so the end marker follows it: D is true. That marker is not automatically the first symbol of any derivation from S, making B false. Thus select A,D. For an ε-production, a predictive parser uses FOLLOW(A) to decide when to take it; it does not put ε into FOLLOW(A).

Original paper, page 46 · Answer key