FIRST and FOLLOW Sets MCQs: 10 Solved Questions Explained

Solve 10 FIRST and FOLLOW practice questions. Each answer explains the rule, propagation step or fixed-point calculation that decides it.

KnowledgeGate Team

Exam prep & CS education

3 Aug 20268 min read

Most FIRST and FOLLOW mistakes are mechanical rather than conceptual: a nullable non-terminal nobody marked, an ε or $ dropped into the wrong set, or a recursive dependency abandoned one pass before it settles. Work all ten questions on paper first, then compare your sets symbol by symbol against the worked derivations. If the grammar notation itself is the obstacle, Parsing in Compiler Design: Top-Down and Bottom-Up Explained sets it up.

1. FIRST and FOLLOW rules to use for every MCQ

For terminal a, FIRST(a) = {a}; add ε to FIRST(A) if A ⇒* ε. In A → X1X2...Xk, scan left to right, adding FIRST(Xi) - {ε} up to and including the first non-nullable symbol; ε joins FIRST(A) only when every Xi is nullable. Put $ in the start symbol's FOLLOW. In A → αBβ, add FIRST(β) - {ε} to FOLLOW(B) and, if β is nullable or absent, FOLLOW(A). FOLLOW excludes ε.

Warm-up: S → AB, A → a | ε, B → b gives FIRST(A) = {a, ε}, FIRST(B) = {b}, FIRST(S) = {a, b}, FOLLOW(S) = {$}, FOLLOW(A) = {b}, FOLLOW(B) = {$}. Nullable A exposes b; final B inherits $.

Iterate circular dependencies until a pass adds nothing. Revise the grammar foundation if needed.

2. FIRST, FOLLOW and the end marker defined (questions 1-2)

Question 1: where ε and the right-end marker belong (multiple-select)

Asked in GATE 2025.

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

  • (A) For a production A → ε, ε will be added to First(A).

  • (B) If there is any input right end marker, it will be added to First(S), where S is the start symbol.

  • (C) For a production A → ε, ε will be added to Follow(A).

  • (D) If there is any input right end marker, it will be added to Follow(S), where S is the start symbol.

Answer: (A) and (D). A → ε adds ε to FIRST(A); the right-end marker belongs to FOLLOW(S). Exact solution.

Question 2: formal definitions of FIRST and FOLLOW

Asked in UGC NET June 2013.

Which is the correct statement(s) for Non-Recursive predictive parser?

S₁: FIRST(α) = { t | α ⇒* tβ for some string β }

S₂: FOLLOW(X) = { a | S ⇒* αXaβ for some strings α and β }

  • (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

Answer: (D) Both statements S₁ and S₂ are correct. S₁ defines t ∈ FIRST(α); S₂ defines a ∈ FOLLOW(X). Exact solution.

3. FOLLOW through nullable suffixes (questions 3-4)

Question 3: FOLLOW(Q) when R is nullable

Asked in GATE 2017.

Consider the following grammar:

p → xQRS

Q → yz | z

R → w | ε

S → y

What is FOLLOW(Q)?

  • (A) {R}

  • (B) {w}

  • (C) {w,y}

  • (D) {w,$}

Answer: (C) {w,y}. FIRST(R) = {w, ε} contributes w; nullable R exposes FIRST(S) = {y}. Non-nullable S blocks $. Exact solution.

Question 4: FOLLOW(R) when S can disappear

Asked in UGC NET August 2024.

Consider the Grammar:

T -> Qx

Q -> RS

R -> y | ε

S -> z | ε

Here x, y, z are terminals and T, Q, R, S are non terminals. What will be the follow set of the non terminal R?

  • (A) {x, y}

  • (B) {y, z}

  • (C) {z, x}

  • (D) {ε}

Answer: (C) {z, x}. FIRST(S) - {ε} = {z} enters FOLLOW(R); nullable S also passes FOLLOW(Q) = {x}, giving {z, x}. Exact solution.

4. Computing FIRST and FOLLOW directly (questions 5-6)

Question 5: FIRST(S) and FOLLOW(A) from four alternatives

Consider the following grammar

S → Aa | bAc | dc | bda

A → d

Which one of the following represents first(S) and follow (A) respectively?

  • (A) {c} , {b, d}

  • (B) {b}, {c}

  • (C) {d}, {c}

  • (D) {b, d} {c, a}

Answer: (D) {b, d} {c, a}. Because A → d, the four alternatives begin with d, b, d, b, so FIRST(S) = {b, d}. The two As precede a and c, so FOLLOW(A) = {a, c}. FIRST concept lesson.

Question 6: FIRST(S) with an explicit ε alternative

Asked in Coal India 2020.

Consider the grammar

S → AbBaCc | ε

A → aAb | ba

B → BBC | cb

C → cCa | ac

Find the First () of S.

  • (A) {a, b, ε}

  • (B) {ε}

  • (C) {a, ε}

  • (D) {a, b, c, ε}

Answer: (A) {a, b, ε}. Non-nullable A gives FIRST(AbBaCc) = {a, b}; S → ε adds ε. Exact solution.

5. FIRST and FOLLOW as fixed points of recursive grammars (questions 7-8)

Question 7: complete FIRST and FOLLOW sets for S, A, B and C

Consider the following grammar:

S → AaB | bC

A → BC ∣ bA

B → aB ∣ ε

C→ a ∣ SA

Let FIRST(X) and FOLLOW(X) denote the standard sets for non-terminal X. Which one of the following options correctly gives FIRST and FOLLOW sets for all variables?

  • (A) FIRST(S) = { a,b }, FOLLOW(S) = { a, b, $ }, FIRST(A) = { a, b }, FOLLOW(A) = { a, b }, FIRST(B) = { a, ε }, FOLLOW(B) = { a,b, $ }, FIRST(C) = { a, b }, FOLLOW(C) = { a, b }

  • (B) FIRST(S) = { a,b }, FOLLOW(S) = { a, b, $ }, FIRST(A) = { a, b }, FOLLOW(A) = { a, b, $ }, FIRST(B) = { a, ε }, FOLLOW(B) = { a,b, $ }, FIRST(C) = { a, b }, FOLLOW(C) = { a, b, $ }

  • (C) FIRST(S) = { a,b }, FOLLOW(S) = { a, b, $ }, FIRST(A) = { a, b }, FOLLOW(A) = { a, b}, FIRST(B) = { a, ε }, FOLLOW(B) = { a,b, $ }, FIRST(C) = { a, b }, FOLLOW(C) = { a, b, $ }

  • (D) FIRST(S) = { a,b }, FOLLOW(S) = { a, b, $ }, FIRST(A) = { a, b }, FOLLOW(A) = { a, b, $ }, FIRST(B) = { a, ε }, FOLLOW(B) = { a,b, $ }, FIRST(C) = { a, b }, FOLLOW(C) = { b, $ }

Answer: (B). The final table is:

Non-terminal

FIRST

FOLLOW

S

{a, b}

{a, b, $}

A

{a, b}

{a, b, $}

B

{a, ε}

{a, b, $}

C

{a, b}

{a, b, $}

$ flows from FOLLOW(S) to final C in S → bC, then final A in C → SA; A → BC returns it to C. Final B in S → AaB inherits FOLLOW(S). Iterate until a pass adds nothing. Options (A) and (C) stop FOLLOW(A) at {a, b} and so lose that $; option (D) trims FOLLOW(C) to {b, $}, although S → bC hands C the whole of FOLLOW(S).

Question 8: FIRST(P) under nullable recursive components

Consider the following grammar, where {#, &, x, y} are terminals:

S → P

P → QR | TQR

Q → Q# | ε

R → & | ε

T → x | y

Select the correct option.

  • (A) FIRST(P) = {#, x, y, ε}

  • (B) FIRST(P) = {#, x, y, &}

  • (C) FIRST(P) = {#, x, y}

  • (D) FIRST(P) = {#, &, x, y, ε}

Answer: (D) FIRST(P) = {#, &, x, y, ε}. Iteration gives FIRST(Q) = {#, ε} and FIRST(QR) = {#, &, ε}; TQR adds {x, y}. Both Q and R are nullable, so P itself derives ε: option (A) drops the & that R contributes once Q vanishes, option (B) drops the ε, and option (C) drops both.

6. Reconstructing productions from given FIRST and FOLLOW sets (question 9)

Question 9: fill three incomplete productions

Asked in GATE 2024.

Consider the following grammar G, with S as the start symbol. The grammar G has three incomplete productions denoted by (1), (2), and (3).

S → daT | (1)

T → aS | bT | (2)

R → (3) | ε

The set of terminals is {a, b, c, d, f}. The FIRST and FOLLOW sets of the different non-terminals are as follows

FIRST(S) = {c, d, f}, FIRST(T) = {a, b, ε}, FIRST(R) = {c, ε}

FOLLOW(S) = FOLLOW(T) = {c, f, $}, FOLLOW(R) = {f}

Which one of the following options CORRECTLY fills in the incomplete productions?

  • (A) (1) S → Rf (2) T → ε (3) R → cTR

  • (B) (1) S → fR (2) T → ε (3) R → cTR

  • (C) (1) S → fR (2) T → cT (3) R → cR

  • (D) (1) S → Rf (2) T → cT (3) R → cR

Answer: (A). S → Rf, T → ε, R → cTR | ε give the stated FIRST sets and FOLLOW(R) = {f}. In cTR, T receives c, f; the cycle between S and T adds $. Exact solution.

7. FOLLOW cardinality, and what to revise next (question 10)

Question 10: cardinality of FOLLOW(S)

Asked in MPPSC 2025.

Consider the following grammar.

S → S#cS | SS | Sε | <S> | a | b | c

The cardinality of Follow(s) is

  • (A) 6

  • (B) 8

  • (C) 5

  • (D) 7

Answer: (D) 7. S is the start symbol, so $ is in FOLLOW(S). In S → S#cS, the first S is followed by #. In S → SS, the first S is followed by FIRST(S) = {<, a, b, c}. In S → <S>, the S is followed by >. Therefore FOLLOW(S) = {$, #, <, >, a, b, c} has seven members; adds nothing new. Exact solution.

The short version

Misses on questions 1 and 2 mean the definitions are the gap: ε belongs to FIRST and never to FOLLOW, and the end marker belongs to FOLLOW(S) and never to FIRST(S). Misses on 3, 4 or 6 mean nullable suffixes: mark every nullable non-terminal before you start, then keep scanning past it instead of stopping. Misses on 7, 8 or 9 mean the fixed point, so keep iterating until a full pass adds nothing. Questions 5 and 10 are bookkeeping, where a miss is usually a skipped alternative rather than a misread rule.

For the phase that feeds tokens into the parser, read Lexical Analysis in Compiler Design. For the whole syntax-analysis sequence taught in order, from grammars through LL(1) tables, GATE Guidance by Sanchit Sir carries it, and GATE CS Exam Preparation collects the rest of the paper. Redo today's misses tomorrow, marking nullability and FOLLOW dependencies as you go.