GateAI
Lexical Analysis

GATE CSE 2023 · Q19

MCQ1 markEasy

Time

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 [\text{A-Za-z}] \\ \text{digit} &\rightarrow [0\text{-}9] \\ \mathbf{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 identifiers? (A double-circle denotes a final state)

Select one answerSingle correct

Pick an option to check

Solution

Step-by-step verified solution

Official answer: C)

Lexical Analysis

The regular expression for a valid identifier is:

id=letter(letter∣digit)∗\text{id} = \text{letter}(\text{letter} \mid \text{digit})^*

To accept strings belonging to this language:

  1. An identifier must start with a letter. The initial transition from the start state on letter correctly reaches an accepting (final) state (the double circle).

  2. After the first letter, any sequence of letter or digit in any arbitrary order can follow zero or more times, returning to the accepting state after each character.

Evaluating the given options:

  • Option (C): After consuming the first letter to reach the final state, it branches non-deterministically via ϵ\epsilon-transitions to read either a letter or a digit, and then returns via an ϵ\epsilon-transition back to the final state. This allows any arbitrary sequence of letters and digits to be accepted. Thus, (C) is correct.

  • Option (A): The transitions and structure do not correctly represent (letter∣digit)∗(\text{letter} \mid \text{digit})^*.

  • Option (B): From the intermediate state, once the machine branches on an ϵ\epsilon-transition into the letter state or digit state, it can only consume that specific type of character repeatedly via the self-loop. It cannot alternate between letters and digits (e.g., it cannot accept strings like a1b2).

  • Option (D): It enforces a repeating sequence of letter followed strictly by digit, rather than allowing an arbitrary combination of (letter∣digit)∗(\text{letter} \mid \text{digit})^*.

Therefore, the correct automaton is given by Option (C).

Try the question first, then check your work.

Think the official key or this write-up is wrong?

Report error or challenge

Examiner trap

The misconception this question tests

This Lexical Analysis previous year question is Q19 of the GATE CSE 2023 paper. Find more GATE CSE PYQs on Lexical Analysis in Compiler Design, or browse all GATE CSE PYQs.

Free diagnostic

Where do you stand for GATE?

Take the 20-minute diagnostic: the 3 topics that cost you the most marks, and a rank range. Or sit 5 related Lexical Analysis PYQs now with no account.

One GATE CSE PYQ every morning

An official question by email at 7 AM IST, with a link to its verified solution. Unsubscribe in one click.

Lexical Analysis in GATE CSE

Lexical Analysis has 7 GATE CSE PYQs across 6 papers from 2011 to 2026. 5 of them are 1-mark MCQs like this one, and it is the only one in GATE CSE 2023.

How GATE tests Lexical Analysis

More from GATE CSE 2023

Share this solution

A plain-text card for WhatsApp or Telegram study groups.

GateAI solution cardGATE CSE 2023 · Q19 · MCQ

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)

Topic-wise GATE CS PYQs with verified steps

Independent practice explanation verified by the GateAI team. GATE is conducted by the IITs; question text follows the official paper.