GATE CSE 2026 Session 2 Q35: Count tokens produced by a lexer for a given string
- Compiler Design
- 1 mark
- NAT
- No negative marking
Question
A lexical analyzer uses the following token definitions
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
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
Source: official GATE 2026 Session 2 CS question paper and final answer key, organised by IIT Guwahati. Question paper · Answer key
More Compiler Design PYQs
- 2026 Session 1 · Q27Classify errors in three C string declarations
- 2026 Session 1 · Q28True statements about LL(1) parsing
- 2026 Session 1 · Q42Redundant (common) subexpressions in blocks B4 and B5 of a CFG
- 2026 Session 1 · Q53Compare two SDDs for type declarations
- 2026 Session 2 · Q41Shift-reduce conflicts in the LR(0) table of a grammar
- 2026 Session 2 · Q45Live variables at the exit of each block in a loop CFG