Question
Consider the following definition of a lexical token id for an identifier in a programming language, using extended regular expressions:
Which one of the following Non-deterministic Finite-state Automata with -transitions accepts the set of valid tokens id?
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 .
- It must begin with a transition on from the start state to an intermediate state.
- The second part is a Kleene star over the union of and . Thompson's construction for introduces -transitions that loop back to the beginning of the sub-expression and allow bypassing via to an accepting state.
- In Option (C), the start state transitions on to a hub, which connects via -transitions to parallel branches for and , with proper feedback loops and exit paths to the final states, precisely implementing the Thompson construction.
Option (C)
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.