D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 2734 - Ambiguity in tokenizing: _._ as a float literal
Summary: Ambiguity in tokenizing: _._ as a float literal
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: x86 Linux
: P2 normal
Assignee: No Owner
URL: http://www.digitalmars.com/d/1.0/lex....
Keywords: spec
Depends on:
Blocks: 3104
  Show dependency treegraph
 
Reported: 2009-03-15 07:53 UTC by Neia Neutuladh
Modified: 2015-06-09 01:21 UTC (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Neia Neutuladh 2009-03-15 07:53:13 UTC
http://www.digitalmars.com/d/1.0/lex.html
http://www.digitalmars.com/d/2.0/lex.html

Under "Floating Literals", the spec says:
DecimalFloat -> DecimalDigits
DecimalFloat -> DecimalDigits . DecimalDigits
DecimalFloat -> . DecimalDigits
etc

DecimalDigits is defined as:
DecimalDigits -> DecimalDigit
DecimalDigits -> DecimalDigit DecimalDigits
DecimalDigit -> [0123456789_]

From this, we can derive:
DecimalFloat -> DecimalDigits . DecimalDigits
-> DecimalDigit . DecimalDigit
-> _ . _

To resolve the ambiguity, _ cannot be allowed as the first character in a float, and it cannot be allowed as the first character after the decimal point.
Comment 1 Unknown W. Brackets 2009-03-29 22:20:05 UTC
It appears DMD 2.026 already works as you suggest; _1.0 is not recognized as a valid float.

However, 1_._1 is, which doesn't seem ambiguous to me.  Once you're after the . and in a FloatLiteral, any characters in [_0-9] should be eaten to finish the float literal.

The spec just needs to be corrected with a new rule that defines 0, NonZeroDigit, and then a repeating of those with DecimalDigits (Decimal is almost fine except its handling of octals.)

-[Unknown]