Practice free →
HomeGATE CSEcomputerscienceCompiler Design › If a programmer writes `1.5e3` in a C-style lang…

If a programmer writes `1.5e3` in a C-style language, the scanner should produce

Aa NUMBER token with literal value 1500.0
Bthree tokens: NUMBER, DOT, NUMBER
Can IDENTIFIER token
Da syntax error
Answer & Solution
Correct answer: A. a NUMBER token with literal value 1500.0
1. `1.5e3` is the scientific notation for $1.5 \times 10^3 = 1500.0$. 2. Scanner rule: a NUMBER lexeme = digits, optional decimal, optional 'e' or 'E' with optional sign, digits. 3. Scanner reads ALL of `1.5e3` as one lexeme (maximal munch), recognises it as a NUMBER token, parses it to the double value 1500.0. 4. So a single NUMBER token is emitted with literal value 1500.0. 5. Option B would split incorrectly (scanner uses maximal munch). Option C would require the lexeme to look like an identifier. Option D is wrong — scientific notation is standard valid syntax. _Source: Bob Nystrom, "Crafting Interpreters", Ch 4.6 (Longer Lexemes — numbers)._
Solve this in the app — GATE CSE practice & 24k+ MCQs →
Related questions