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 Analyzer Output in Compiler Design
In compiler design, the lexical analyzer’s sole output is a stream of tokens derived from the source code character stream.
- It scans characters left‑to‑right, grouping them into lexemes that match language patterns.
- Each lexeme is classified into a token category (e.g., ID, NUM, PLUS) possibly with attributes.
- The token stream is handed to the parser, which builds the parse tree or AST.
- Machine code, intermediate code, and parse trees are produced in later compilation phases, not by the lexer.
Regular Languages Among Given Options: A Formal Language Analysis
Correct Answer: Eliminating Immediate Left Recursion \(A \rightarrow A\alpha / \beta\)