Don't accept illegal octal integer literals as doubles.
Don't accept illegal octal integer literals as doubles.

The original lexer rule

 $digit+ @exponent? [dD]?

would match any string of digits, including those that start with a
zero '0'. This means that the lexer would read what should be
interpreted as illegal octal literals as doubles. For example, the
input text

 09

would be lexed as

 DoubleTok 9

The problem with the original rule is it allows interpreting

 $digit+

as a double literal, which is not legal according to the grammar in
Chapter 3 of the Java Language Specification (3rd edition). The
productions of the grammar say that either the exponent is necessary,
or the floating point type indicator is necessary, but they cannot
both be left off. In order to address that, I've replaced the original
rule with the two rules

 $digit+ @exponent
 $digit+ @exponent? [dD]

Now, this by itself trades one error for another. Now the text

 09

lexes as two tokens

 [IntTok 0, IntTok 9]

I can't find a place where the JLS says this should be a lexical
error, although it would certainly be grammatically incorrect to have
consecutive integer literals. So I tried it out with javac from JDK
1.6.0_20. It says

  integer number too large: 09

The message is rather confusing, since "09" doesn't look "too large",
but I think it's trying to say that "09" contains a digit which out of
range for an octal integer literal.

It seems like the best approach is to absorb all the digits into the
text of a potential integer literal, and complain when there are
non-octal digits.

To implement this, I've used '$digit' instead of '$octdig' in the
lexer rules for matching octal integer literals, and defined a
'pickyReadOct' utility that invokes 'readOct'. If 'head . readOct'
returns a non-empty suffix, 'pickyReadOct' calls 'error' with a
reasonable message about illegal octal digits.


exemplator/java-parser,exemplator/java-parser,alosich/language-java,karshan/language-java