GATE Computer ScienceVery hardGATE CS (PYQ pattern)

A Pascal-like scanner uses longest match (ties to the earlier rule) with rules: FLOAT = [0-9]+\.[0-9]*; INT = [0-9]+; RANGE = \.\.; DOT = \.; ID = [a-z]+. How many tokens are produced for the input "1..5.x3.7..2" (no spaces)?

  1. A. 6
  2. B. 9
  3. C. 8
  4. D. 7

Correct answer: D. 7

Tokens: 1. | . | 5. | x | 3.7 | .. | 2. '1..5' scans as FLOAT '1.' then DOT, then INT 5, because the longest match at '1' is '1.' (2 chars) rather than INT '1'.

More Compiler Design questions

Exams that ask this topic