IAE Academy

GATE 2025 CS1 Q.46: solution and answer

GATE 2025 · CS1Q.46 · 2 marks · MSQ

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

  1. (A)

    For a production , will be added to .

  2. (B)

    If there is any input right end marker, it will be added to , where is the start symbol.

  3. (C)

    For a production , will be added to .

  4. (D)

    If there is any input right end marker, it will be added to , where is the start symbol.

See the question in the paper

Answer and solution

ANSWER

Options A and D are true.

Official answer: A, DSource: Official answer key, GATE 2025 CS1 (IIT Roorkee)

  1. holds the terminals that can begin a string derived from , plus if .

  2. (A) With the production , derives the empty string, so . TRUE.

  3. (B) The end marker $ is not a grammar symbol, so it is never the first symbol of a string derived from and never enters any FIRST set. FALSE.

  4. (C) holds the terminals that can come right after , plus the end marker. is not a terminal and never appears in a FOLLOW set. FALSE.

  5. (D) The first rule for FOLLOW is: put $ in for the start symbol , because the input ends right after the whole string derived from . TRUE.

  6. Correct options: A and D.

KEY IDEA

belongs only in FIRST sets (when a symbol can derive the empty string); the end marker $ belongs only in FOLLOW sets, starting with for the start symbol.

WATCH OUT FOR

Mixing up the two sets: adding to a FOLLOW set because of , or adding the end marker $ to .

From the GATE 2025 CS1 paper. Every question of this paper · Download the full paper · All 13 Parsing questions, with notes

More Parsing questions