FIRST Set for Terminals: Choosing the Correct Answer
In context-free grammar parsing, the FIRST function is defined over grammar symbols. For a terminal symbol , the string that derives from starts with itself, so FIRST rather than containing . This directly answers the multiple-choice question: if is a terminal then FIRST is .
A useful related notion is 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 in the standard CFG definition.
Footnotes
-
(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. ↩
-
(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. ↩
-
(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. ↩
-
(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 is a terminal then FIRST is:
| Option | Meaning | Is it correct for terminals? |
|---|---|---|
| (i) | Empty string is a possible first terminal | No—terminals don’t derive under CFG FIRST definition 2 |
| (ii) | is the only possible first terminal | Yes 2 |
| (iii) | Kleene star (a regex operator), not a FIRST-set element form | Not the right concept for FIRST sets in CFG parsing |
| (iv) | Also regex-like form, not a FIRST-set definition | Not the right concept for FIRST sets in CFG parsing |
Therefore, the correct answer is (ii) . 2
Footnotes
-
(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. ↩
-
(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. ↩
-
(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
-
(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)
- 1Step 1
Check whether is a grammar terminal or a nonterminal nonterminal.
- 2Step 2
If is a terminal, then FIRST is the singleton set containing itself, i.e., FIRST.
- 3Step 3
Do not include for terminals because terminals do not derive the empty string; belongs to FIRST only for nullable symbols (typically certain nonterminals).
Rule of Thumb
In CFGs, for any terminal . shows up only when a symbol can derive the empty string (i.e., is nullable).
Common Confusion: Regex operators vs FIRST sets
Options like or 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 1Classify tokens as terminals and variables as nonterminals."
Build FIRST sets
Step 2Use the terminal rule (FIRST(terminal) = {terminal}) and ε/derivation rules for nonterminals."
Use FIRST in LL(1)
Step 3FIRST guides which production to choose based on the next input terminal."
FIRST Set Rapid Checks
Knowledge Check
If x is a terminal then FIRST(x) is
Explore Related Topics
Lexical Analysis Token Counting: `while(count<=10) count = count + 1;`
The course explains how a lexical analyzer tokenizes the C statement while(count<=10) count = count + 1; and why the standard exam answer is 11 tokens.
- Keywords, identifiers, literals, operators, and delimiters each count as one token; whitespace is ignored.
<=is recognized as a single relational‑operator token due to the longest‑match rule.- The full lexical split shows 12 visible symbols, but typical MCQ conventions omit one delimiter, giving 11 tokens.
- Understanding token categories helps avoid common exam traps such as counting delimiters incorrectly.
Linear Grammar in the Chomsky Hierarchy (CF Grammar with ≤ 1 Nonterminal on RHS)
Symbol Table Attributes: Why the Correct Answer Is “All of These”