You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Reason: the parser parses the string into an java.lang.Integer object
Workaround: Use tokens, e.g.
token MY_DIGITS digit+;
and process afterwards the string.
Possible solution: Use a java.math.BigInteger field instead of java.lang.Integer, so that the information that the field is numeric (and integer) is preserved without bounds on its precision.
A similar problem arises with the grammar
Label. Category ::= Double;
In that case it is subtler because an overflowing number (wrt the ieee 64 bits double format) is converted into a java.lang.Double to the value Infinity. Therefore the parsing does not fail, but implicitly the semantics of ieee 64 bits floating-point numbers is given to the parsed string.
A solution coherent with the one about integers is to use java.math.BigDecimal instead of java.lang.Double
The text was updated successfully, but these errors were encountered:
andreasabel
changed the title
Integer and Double built-in tokens in Java can give problems in parsing
Java: use BigInteger and BigDecimal (?) for Integer and Double built-in tokens
Jan 2, 2020
BNFC 2.5., with -java option
Consider the following grammar:
The generated parser accepts the string
but fails in
Reason: the parser parses the string into an
java.lang.Integer
objectWorkaround: Use tokens, e.g.
and process afterwards the string.
Possible solution: Use a
java.math.BigInteger
field instead ofjava.lang.Integer
, so that the information that the field is numeric (and integer) is preserved without bounds on its precision.A similar problem arises with the grammar
In that case it is subtler because an overflowing number (wrt the ieee 64 bits double format) is converted into a
java.lang.Double
to the valueInfinity
. Therefore the parsing does not fail, but implicitly the semantics of ieee 64 bits floating-point numbers is given to the parsed string.A solution coherent with the one about integers is to use
java.math.BigDecimal
instead ofjava.lang.Double
The text was updated successfully, but these errors were encountered: