Question

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)∗\begin{aligned} \text{letter} &\rightarrow [A\text{-}Za\text{-}z] \\ \text{digit} &\rightarrow [0\text{-}9] \\ \text{id} &\rightarrow \text{letter} (\text{letter} \mid \text{digit})^* \end{aligned}

Which one of the following Non-deterministic Finite-state Automata with ϵ\epsilon-transitions accepts the set of valid tokens id?

Choose one option
Official answer and solution
Official answer
C
From
Official GATE 2023 answer key

Solution

Analyze Thompson's NFA construction for concatenation and Kleene star.

The regular expression is letter(letter∣digit)∗\text{letter} (\text{letter} \mid \text{digit})^* .

  1. It must begin with a transition on letter\text{letter} from the start state to an intermediate state.
  2. The second part is a Kleene star over the union of letter\text{letter} and digit\text{digit}. Thompson's construction for r∗r^* introduces ϵ\epsilon-transitions that loop back to the beginning of the sub-expression and allow bypassing via ϵ\epsilon to an accepting state.
  3. In Option (C), the start state transitions on letter\text{letter} to a hub, which connects via ϵ\epsilon-transitions to parallel branches for letter\text{letter} and digit\text{digit}, with proper feedback loops and exit paths to the final states, precisely implementing the Thompson construction.
Final answer

Option (C)

Common trap

Choosing an automaton that accepts the empty string or allows a digit as the first symbol.

The answer is the one in the official GATE answer key. The solution is this site's own explanation.

Source

Paper
GATE 2023 Computer Science and Information Technology (CS)
Question
19 of 65
Section
Computer Science and Information Technology

Report an error in this question

GATE questions are the work of the organising institutes. This site is independent and is not affiliated with them.