Consider the following definition of a lexical token id for an identifier in a programming language, using extended regular expressions:
letter → [A-Za-z]
digit → [0-9]
id → letter (letter | digit)*
Which one of the following Non-deterministic Finite-state Automata with ε-transitions accepts the set of valid identifiers? (A double-circle denotes a final state)
Tap to open full sizeFigure description
Four NFAs with ε-transitions, each starting from a start state (arrow in). (A) Start state q0 has a 'letter' transition to a double-circle final state q1, and also an ε-transition from q0 to q1 (curved arrow below). q1 has a self-loop labelled 'letter' and 'digit'. (B) Start q0 --letter--> double-circle q1. q1 has an ε-transition to a double-circle state q2 and another ε-transition to a double-circle state q3. q2 has a self-loop labelled 'letter'; q3 has a self-loop labelled 'digit'. (C) Start q0 --letter--> double-circle q1. q1 --ε--> q2 --letter--> q3 --ε--> q5, and q1 --ε--> q4 --digit--> q6 --ε--> q5, where q5 is a non-final state with an ε-transition back to q1. (D) Start q0 --letter--> double-circle q1 --letter--> q2 --digit--> q3, and q3 has an ε-transition back to q1.
- (A)
Figure — NFA (A) as described
- (B)
Figure — NFA (B) as described
- (C)
Figure — NFA (C) as described
- (D)
Figure — NFA (D) as described