Combined grammar changes for binary literals and underscores in literals

Joseph D. Darcy Joe.Darcy at Sun.COM
Wed Jul 15 14:22:32 PDT 2009


Hello.

Getting around to some grammatical hacking, below is a grammar I think 
properly captures the desired changes for combining the binary literals 
and underscores in literals proposals.  This grammar does *not* include 
support for unsigned literals or autosizing literals.

The basic approach is to redefine the FooDigits productions to be a 
non-empty sequence of Foo digits and underscores starting and ending 
with a Foo digit rather than just a non-empty sequence Foo digits.  Each 
FooDigits nonterminal has two rules, one for a single digit and one for 
two or more digits.  The rules for two or more digits force a true 
digit, rather than an underscore, as the first and last character.

Changing the FooDigits definitions allows underscores in both integer 
and floating-point literals.  In more detail:
 
* Replace the productions Digits, HexDigits, OctalDigits, and  in JLSv3 
3.10.1 as shown below
* Add productions for BinaryDigits
* Add rules for FooDigitsAndUnderscores and FooDigitOrUnderscore
* Add productions to DecimalNumeral and OctalNumeral:
* Add a rule for Underscores

IntegerLiteral:
        DecimalIntegerLiteral
        HexIntegerLiteral
        OctalIntegerLiteral
        BinaryIntegerLiteral         // New

BinaryIntegerLiteral:
        BinaryNumeral IntegerTypeSuffix_opt
 
BinaryNumeral:
        0 b BinaryDigits
        0 B BinaryDigits


DecimalNumeral
   0
   NonZeroDigit Digits_opt
   NonZeroDigit Underscores Digits // New
 
Underscores
    _
    Underscores _
 
Digits:
    Digit
    Digit DigitsAndUnderscores Digit
 
DigitsAndUnderscores:
    DigitOrUnderscore
    DigitsAndUnderscores DigitOrUnderscore
 
DigitOrUnderscore
    Digit
    _
 
 
HexDigits:
    HexDigit
    HexDigit HexDigitsAndUnderscores HexDigit
 
HexDigitsAndUnderscores:
    HexDigitOrUnderscore
    HexDigitsAndUnderscores HexDigitOrUnderscore
 
HexDigitOrUnderscore
    HexDigit
    _
 
OctalNumeral:
    0 OctalDigits
    0 Underscores OctalDigits // New
 
OctalDigits:
    OctalDigit
    OctalDigit OctalDigitsAndUnderscores OctalDigit
 
OctalDigitsAndUnderscores:
    OctalDigitOrUnderscore
    OctalDigitsAndUnderscores OctalDigitOrUnderscore
 
OctalDigitOrUnderscore
    OctalDigit
    _
 
BinaryDigits:
    BinaryDigit
    BinaryDigit BinaryDigitsAndUnderscores BinaryDigit
 
BinaryDigitsAndUnderscores:
    BinaryDigitOrUnderscore
    BinaryDigitsAndUnderscores BinaryDigitOrUnderscore
 
BinaryDigitOrUnderscore
    BinaryDigit
    _

BinaryDigit: one of
        0 1

-Joe



More information about the coin-dev mailing list