Skip to content
GATEiit

GATE CSE 2026 Session 2 Q35: Count tokens produced by a lexer for a given string

Question

A lexical analyzer uses the following token definitions

letter→[A-Za-z]digit→[0-9]id→letter (letter∣digit)∗number→digit+ws→(blank∣tab∣newline)+\begin{aligned} letter &\rightarrow [A\text{-}Za\text{-}z] \\ digit &\rightarrow [0\text{-}9] \\ id &\rightarrow letter\,(letter \mid digit)^* \\ number &\rightarrow digit^+ \\ ws &\rightarrow (blank \mid tab \mid newline)^+ \end{aligned}

For the string given below,

x1 23mm 78 y 7z zz5 14A 8H AaYcD

the number of tokens (excluding ws) that will be produced by the lexical analyzer is __________. (answer in integer)

Try it: numerical answer: type the value

Numerical answer. No negative marking.
Show answer and explanation

Answer: 13 (official GATE 2026 final answer key)

Concept used: The lexer uses longest match; an identifier must start with a letter, so a digit run ends before a letter.

First step: Split a word like 23mm into the number 23 and the id mm, then count tokens word by word.

Full step-by-step solution

Detailed working, common mistakes and linked mock tests will be available with a free GATEiit account. Log-in is coming soon.

Share this question

WhatsAppDownload image

Source: official GATE 2026 Session 2 CS question paper and final answer key, organised by IIT Guwahati. Question paper · Answer key