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)?
- A. (4, 12)
- B. (4, 7)
- C. (4, 10)
- 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
- A scanner generator is given the rules, in this order: (1) if → IF; (2) [a-z][a-z0-9] → ID; (3) [0-9]+ → NUM. It uses the longest match…
- The Thompson construction (Aho–Sethi–Ullman style: a symbol gets 2 states; union and star each add a new start and a new final state…
- In the Thompson NFA for (a|b), each symbol machine has 2 states and 1 non-ε edge; union and star add a new start and final state with 4…
- A floating-point literal is defined over the symbols d (digit), '.', e and s (sign) as d⁺ ( . d⁺ )? ( e s? d⁺ )?. How many states does the…
- A C comment is / followed by any text that does not contain / followed by / . Over the alphabet { /, , x } the language is /([^]|+[^/])+/…
- A flow graph has nodes 1 to 10, entry node 1, and edges 1→2, 2→3, 3→4, 4→5, 5→3, 4→6, 6→7, 7→2, 7→8, 8→9, 9→8, 9→10, 6→10, 3→9. A back…