GATE Computer ScienceVery hardGATE CS (PYQ pattern)

A lexer uses longest match, breaking ties in favour of the rule listed first, with rules: KW = if | then; ID = [a-z][a-z0-9]*; NUM = [0-9]+(\.[0-9]+)?; REL = < | <= | <> | = | > | >=. White space separates tokens and is discarded. How many tokens does it return for the input "if1 if x<=y>=3.5<>1if=12"?

  1. A. 11
  2. B. 9
  3. C. 12
  4. D. 14

Correct answer: C. 12

Tokens: if1 if x <= y >= 3.5 <> 1 if = 12. 'if1' is one ID (longer than KW 'if'), 'if' ties and goes to KW, and '1if' splits into NUM 1 and KW if: 12 tokens.

More Compiler Design questions

Exams that ask this topic