GATE Computer ScienceVery hardGATE CS

A generated scanner for the token set { a, abcd, b, c, d } always returns the longest accepting prefix, and if the DFA reaches the dead state it backs up to the last accepting position. For the input abcabcd the scanner returns a sequence of tokens. Counting every character the DFA looks at, including the character that sends it into the dead state (and counting a character again each time it is looked at after backing up), what is the pair (number of tokens, number of characters examined)?

  1. A. (4, 12)
  2. B. (4, 7)
  3. C. (4, 10)
  4. D. (7, 12)

Correct answer: A. (4, 12)

Position 0: the DFA reads a, b, c and then a (dead) = 4 reads, returns a. Then b (read b and c: 2 reads), c (read c and a: 2 reads), and finally abcd (4 reads, end of input). Tokens: a, b, c, abcd. Total reads 4 + 2 + 2 + 4 = 12, which exceeds the input length 7 because of back-up.

More Compiler Design questions

Exams that ask this topic