GATE CS 2023 · Question 19 · Compiler Design · Multiple choice (MCQ) · 1 mark · −1/3 for a wrong answer

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)

  1. (A) Two states. Start state q0 (single circle, incoming start arrow) and q1 (double circle, final). Transition q0 to q1 labelled 'letter'. A second transition q0 to q1 labelled epsilon. q1 has a self-loop labelled 'letter, digit'.
    Two states. Start state q0 (single circle, incoming start arrow) and q1 (double circle, final). Transition q0 to q1 labelled 'letter'. A second transition q0 to q1 labelled epsilon. q1 has a self-loop labelled 'letter, digit'.
  2. (B) Four states. Start state q0 (single circle, incoming start arrow). q0 to q1 labelled 'letter'; q1 is a double circle (final). q1 to q2 labelled epsilon; q2 is a double circle (final) with a self-loop labelled 'letter'. q1 to q3 labelled epsilon; q3 is a double circle (final) with a self-loop labelled 'digit'.
    Four states. Start state q0 (single circle, incoming start arrow). q0 to q1 labelled 'letter'; q1 is a double circle (final). q1 to q2 labelled epsilon; q2 is a double circle (final) with a self-loop labelled 'letter'. q1 to q3 labelled epsilon; q3 is a double circle (final) with a self-loop labelled 'digit'.
  3. (C) Seven states. Start state q0 (single circle, incoming start arrow). q0 to q1 labelled 'letter'; q1 is a double circle (final). Upper branch: q1 to q2 labelled epsilon, q2 to q3 labelled 'letter', q3 to q6 labelled epsilon. Lower branch: q1 to q4 labelled epsilon, q4 to q5 labelled 'digit', q5 to q6 labelled epsilon. A long arc from q6 back to q1 labelled epsilon. Only q1 is final; q0, q2, q3, q4, q5, q6 are single circles.
    Seven states. Start state q0 (single circle, incoming start arrow). q0 to q1 labelled 'letter'; q1 is a double circle (final). Upper branch: q1 to q2 labelled epsilon, q2 to q3 labelled 'letter', q3 to q6 labelled epsilon. Lower branch: q1 to q4 labelled epsilon, q4 to q5 labelled 'digit', q5 to q6 labelled epsilon. A long arc from q6 back to q1 labelled epsilon. Only q1 is final; q0, q2, q3, q4, q5, q6 are single circles.
  4. (D) Four states. Start state q0 (single circle, incoming start arrow). q0 to q1 labelled 'letter'; q1 is a double circle (final). q1 to q2 labelled 'letter', q2 to q3 labelled 'digit'. An arc from q3 back to q1 labelled epsilon. Only q1 is final.
    Four states. Start state q0 (single circle, incoming start arrow). q0 to q1 labelled 'letter'; q1 is a double circle (final). q1 to q2 labelled 'letter', q2 to q3 labelled 'digit'. An arc from q3 back to q1 labelled epsilon. Only q1 is final.
Answer

Answer (C)

Answer from the official GATE CS 2023 answer key.

The step-by-step solution, where available, is part of GATE CS Pro. See what Pro includes