GATE Computer ScienceVery hardGATE CS (PYQ pattern)

A scanner (longest match, ties to the earlier rule) has rules: COMMENT = //[^newline]*; STR = "[^"]*"; DIV = /; EQ = ==; ASSIGN = =; ID = [a-z]+; white space (including newline) is skipped. How many tokens (excluding white space) does it produce for the input whose first line is x=="a//b"/y//z/w and whose second line is =q ?

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

Correct answer: B. 8

Tokens: x | == | "a//b" | / | y | //z/w | = | q; the // inside the string literal does not start a comment because the string is matched first from the quote, and the real // swallows 'z/w' to the end of the line.

More Compiler Design questions

Exams that ask this topic