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 ) that will be produced by the lexical analyzer is __________. (answer in integer)
Official answer and solution
- Official answer
- 13
- From
- Official GATE 2026 answer key
Solution
Apply the longest-match (maximal munch) rule to each whitespace-separated chunk.
By the maximal-munch rule, a chunk starting with a digit matches up to the first letter, and the remaining suffix starting with a letter matches :
x1<id, x1>(1 token)23mm<number, 23>,<id, mm>(2 tokens)78<number, 78>(1 token)y<id, y>(1 token)7z<number, 7>,<id, z>(2 tokens)zz5<id, zz5>(1 token)14A<number, 14>,<id, A>(2 tokens)8H<number, 8>,<id, H>(2 tokens)AaYcD<id, AaYcD>(1 token)
Total tokens (excluding ) .
13
Counting whitespace-separated words (9) without splitting 23mm, 7z, 14A, and 8H into <number> followed by <id>.
The answer is the one in the official GATE answer key. The solution is this site's own explanation.
Source
- Paper
- GATE 2026 Computer Science and Information Technology - Session 2 (CS2)
- Question
- 35 of 65
- Section
- Computer Science and Information Technology
Report an error in this question
GATE questions are the work of the organising institutes. This site is independent and is not affiliated with them.