Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
[Bug] Java.flex example file can't handle most negative int litera [sf#95] #97
Reported by mcspanky on 2008-07-04 03:26 UTC
This is the same representation problem that causes Math.abs(int) to return negative values when called with Integer.MIN_VALUE.
changed the title from
Java.flex example file can't handle most negative int litera
[Bug] Java.flex example file can't handle most negative int litera [sf#95]
Feb 15, 2015
Commented by lsf37 on 2008-07-27 07:21 UTC
This is now fixed in revision 381 of the repository.
I've added a "-"? to the definition of decimal, hex and oct literals. This only works if there is no whitespace between the minus and the digits, but my reading of the standard is that - 2147483648 (with a white space between the minus and the number) is to be lexed as unary minus and a (too large) int literal and should therefore be rejected.
Workaround for current release: add "-"? to the definition of the Dec, Hex, and Oct Literal macros.
Commented by nobody on 2008-07-27 17:28 UTC
Will this still properly parse x = y-3 ? Wouldn't the RHS lex as two tokens, an identifier and a literal, with no operator?
In my project, I solved this by having the lexer return null for the too-big literal, and leave it up to the parser to turn unary-minus-then-literal into a literal, with special case code if the literal value is null.
Commented by lsf37 on 2008-08-13 07:09 UTC
You are perfectly right, of course, this breaks normal parsing of binary minus.
I have reverted the previous "fix".
I'd propose to match the number 2147483648 explicitly and return -1 in this case. Since all other numbers must be non-negative this should uniquely indicate MIN_INT if it occurs together with unary minus in the parser. (Very similar to what you suggest).
Does this sound better?
Commented by lsf37 on 2009-01-31 06:54 UTC
I've now fixed this in revision r383 in the repository. The solution with matching just 2147483648 separately