FIRST Set for Terminals: Choosing the Correct Answer

FIRST Set for Terminals: Choosing the Correct Answer

Verified Sources
Sep 13, 2026

In context-free grammar parsing, the FIRST function is defined over grammar symbols. For a terminal symbol xx, the string that derives from xx starts with xx itself, so FIRST(x)=x(x)=\\{x\\} rather than containing ϵ\epsilon. This directly answers the multiple-choice question: if xx is a terminal then FIRST(x)(x) is (ii)x(ii) \\{x\\}.

A useful related notion is epsilon: ϵ\epsilon is included in a FIRST set only when a nonterminal (or symbol) can derive the empty string, i.e., when the symbol is nullable; terminals do not derive ϵ\epsilon in the standard CFG definition.

4

Footnotes

  1. (Formal definition source) FIRST sets and ε rules in CFGs. https://en.wikipedia.org/wiki/LL_parser#First_and_follow_sets - Explains FIRST/FOLLOW and conditions for ε inclusion.

  2. (Formal rule) FIRST of terminal symbol. https://en.wikipedia.org/wiki/LL_parser#First_and_follow_sets - Includes the base case FIRST(a) = {a} for terminals.

  3. (Nullable/ε relationship) Nullable symbols and how ε enters FIRST. https://en.wikipedia.org/wiki/Nullable_language - Background on nullable/empty-string derivations used in FIRST computation.

  4. (FIRST set base cases) FIRST computation rules for terminals and ε. https://en.wikipedia.org/wiki/First_and_follow_sets - Summarizes FIRST-set definitions and base cases.

FIRST and FOLLOW Sets (CFG Parsing) — Quick Explanation

Interpreting the options

The question asks: If xx is a terminal then FIRST(x)(x) is:

OptionMeaningIs it correct for terminals?
(i) ϵ\epsilonEmpty string is a possible first terminalNo—terminals don’t derive ϵ\epsilon under CFG FIRST definition 2
(ii) {x}\{x\}xx is the only possible first terminalYes 2
(iii) xx^*Kleene star (a regex operator), not a FIRST-set element formNot the right concept for FIRST sets in CFG parsing
(iv) xxxx^*Also regex-like form, not a FIRST-set definitionNot the right concept for FIRST sets in CFG parsing

Therefore, the correct answer is (ii) {x}\{x\}. 2

Footnotes

  1. (Formal definition source) FIRST sets and ε rules in CFGs. https://en.wikipedia.org/wiki/LL_parser#First_and_follow_sets - Explains FIRST/FOLLOW and conditions for ε inclusion.

  2. (Nullable/ε relationship) Nullable symbols and how ε enters FIRST. https://en.wikipedia.org/wiki/Nullable_language - Background on nullable/empty-string derivations used in FIRST computation.

  3. (Formal rule) FIRST of terminal symbol. https://en.wikipedia.org/wiki/LL_parser#First_and_follow_sets - Includes the base case FIRST(a) = {a} for terminals. 2 3 4

  4. (FIRST set base cases) FIRST computation rules for terminals and ε. https://en.wikipedia.org/wiki/First_and_follow_sets - Summarizes FIRST-set definitions and base cases. 2

Compute FIRST for a Terminal (CFG Rule)

  1. 1
    Step 1

    Check whether xx is a grammar terminal or a nonterminal nonterminal.

  2. 2
    Step 2

    If xx is a terminal, then FIRST(x)(x) is the singleton set containing xx itself, i.e., FIRST(x)={x}(x)=\{x\}.

  3. 3
    Step 3

    Do not include ϵ\epsilon for terminals because terminals do not derive the empty string; ϵ\epsilon belongs to FIRST only for nullable symbols (typically certain nonterminals).

Rule of Thumb

In CFGs, FIRST(a)={a}\text{FIRST}(a)=\{a\} for any terminal aa. ϵ\epsilon shows up only when a symbol can derive the empty string (i.e., is nullable).

Common Confusion: Regex operators vs FIRST sets

Options like xx^* or xxxx^* are regex-style expressions, not FIRST-set outputs. FIRST sets are sets of terminals that can appear first in derivations, not regex closures.

Quick FAQs

How FIRST(x) behaves for terminals vs nullable nonterminals

Conceptual comparison (not numeric data): membership of ε and x

Where the FIRST rule comes into parsing

Define grammar symbols

Step 1

Classify tokens as terminals and variables as nonterminals."

Build FIRST sets

Step 2

Use the terminal rule (FIRST(terminal) = {terminal}) and ε/derivation rules for nonterminals."

Use FIRST in LL(1)

Step 3

FIRST guides which production to choose based on the next input terminal."

FIRST Set Rapid Checks

1 / 3
Question · Term

FIRST(x) when x is a terminal?

Click to reveal
Answer · Definition

FIRST(x) = {x}. Terminals do not include ε.

Knowledge Check

Question 1 of 3
Q1Single choice

If x is a terminal then FIRST(x) is