GATE / CS ARCHIVE

GATE CSE 1995 / QUESTION 1.9

Regular expression for identifiers

Theory of Computation · Regular Expressions & Languages · Full GATE CSE 1995 paper

GATE 1995, Q1.9 1 mark · MCQ
Report issue

Regular Expressions & Languages

Question 1.9, GATE 1995: An identifier is one letter followed by zero or more letters or digits. With letter set L and digit set D, choose its expression.
Tap to enlarge
Your answer
Answer & solution

Answer: B: L(L∪D)* (no official key was published)

The initial L enforces exactly one initial letter. Every subsequent character may independently be a letter or digit, represented by L∪D, and the star allows zero or more such characters. Thus a one-letter identifier is allowed, but an empty identifier or one beginning with a digit is not. Expressions that star an alternating letter-digit pair impose an unjustified pattern, while starring or plussing L∪D alone permits a digit first. The concatenation L(L∪D)* captures precisely the requirement.

Original paper, page 1