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)._
Keep practising Compiler Design
Browse all Compiler Design questions for GATE CSE, or explore more Computer Science topics.
Related questions
The FOLLOW(A) set in LL parsing isThe FIRST(α) set of a string α in LL parsing isAfter the parser produces an AST, the next compiler phase is typicallyA SHIFT/REDUCE CONFLICT in an LR parser occurs whenLL parsers (recursive descent) parse from thePANIC MODE error recovery in a parser works byWhat is a SYNTAX ERROR?How does a parser typically encode OPERATOR PRECEDENCE in the grammar?