GATE / CS ARCHIVE

GATE CSE 2023 / QUESTION 19

GATE CSE 2023 Q19

Compiler Design · Lexical Analysis · Full GATE CSE 2023 paper

GATE 2023, Q19 1 mark · MCQ
Report issue

Lexical Analysis

Question 19, GATE 2023: Identifiers match letter(letter|digit)*, with letter in A–Z or a–z and digit in 0–9. Choose the equivalent ε-NFA: A permits skipping the initial letter and then loops on letters/digits; B after the initial letter branches into an all-letter loop or an all-digit loop; C after the initial letter reaches an accepting hub, from which either a letter or digit branch can be selected by ε-transitions and returned to repeatedly; D after the initial letter repeats letter-then-digit pairs. The source diagrams are linked for exact state layouts.
Tap to enlarge
Your answer
Answer & solution

Official answer: C

A valid identifier begins with one letter and then permits any mixture of letters and digits, including an empty suffix. In C the first letter reaches an accepting state; each repeated epsilon-selected letter/digit branch returns there through the outer epsilon edge. A wrongly accepts epsilon and leading digits; B forces the suffix to be all letters or all digits; D only permits letter-digit pairs after the first letter. Thus C.

Teaching detail. Test a candidate recognizer against boundary cases: a single letter must be accepted, an initial digit must be rejected, and the empty word must be rejected. Then test mixing in the suffix, such as a1b2. The accepting hub of C allows stopping immediately after the first letter and returning after each one-symbol suffix choice. An ε-transition changes state without consuming input; it does not allow an initial digit unless it bypasses the required initial-letter transition. These tests reveal why merely having letter and digit edges somewhere is insufficient.

Original paper, page 16 · Answer key