Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Java: use BigInteger and BigDecimal (?) for Integer and Double built-in tokens #59

Open
gapag opened this issue Aug 30, 2013 · 0 comments

Comments

@gapag
Copy link

gapag commented Aug 30, 2013

BNFC 2.5., with -java option

Consider the following grammar:

Label. Category ::= Integer;

The generated parser accepts the string

1111111111

but fails in

11111111112

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

@andreasabel 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant