GATE Computer ScienceHardGATE CS
A scanner discards comments, which begin with /* and end at the FIRST */ (comments do not nest). Identifiers are letters, and * and / are separate one-character operator tokens. For the input x /* a /* b */ c */ y how many tokens does the scanner return?
- A. 2
- B. 4
- C. 5
- D. 6
Correct answer: C. 5
The comment runs from the first /* to the first */, so it covers /* a /* b */. The remaining text c */ y is scanned normally as c, *, /, y, and with the leading x there are 5 tokens. A scanner with nested comments would return only x and y.
More Compiler Design questions
- A C lexer uses maximal munch. How many tokens does it produce for the line int x = a++ + --b >= 3 ? 1 : 0; (whitespace is ignored)?
- For the grammar S → A B c; A → a A | ε; B → b B | ε, how many terminals are in FIRST(S)?
- For the standard expression grammar E → T E′; E′ → + T E′ | ε; T → F T′; T′ → F T′ | ε; F → ( E ) | id, how many symbols (including ) are…
- How many states does the canonical LR(0) collection of the augmented grammar S′ → S; S → A A; A → a A | b contain?
- What is the number of states in the minimal DFA for the regular expression (a|b)abb?
- Three-address code (at most one operator per instruction, the last instruction assigning to x) is generated for x = ab + c(d − e) − f/g…