Reputation: 11
here is one of the rule I have seen in java.g4:
DecimalLiteral : ('0' | '1'..'9' '0'..'9'*) IntegerTypeSuffix? ;
Why not writing it this way:
DecimalLiteral : ('0'..'9'+) IntegerTypeSuffix? ;
Is there anything I'm missing ? Thank you for your feedback
Regards Philippe Frankson
Upvotes: 1
Views: 715
Reputation: 99939
The intent is to have 0
be a DecimalLiteral
, but all other integers starting with 0
be an OctalLiteral
.
I would prefer to use a pair of rules like this:
OctalLiteral : '0'+ [1-7] [0-7]* IntegerTypeSuffix?;
DecimalLiteral : [0-9]+ IntegerTypeSuffix?;
And then defer validation of invalid octal integers (which this pair of rules would still accept as a DecimalLiteral
) to a later step in the parsing process.
Upvotes: 4