-
Notifications
You must be signed in to change notification settings - Fork 117
[Bug] Java.flex example file can't handle most negative int litera [sf#95] #97
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
Comments
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. |
Updated by lsf37 on 2008-07-27 07:21 UTC
|
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? Cheers, |
Updated by lsf37 on 2008-08-13 07:10 UTC
|
Commented by mcspanky on 2008-08-13 10:55 UTC Yes, that sounds great! Is this scanner used by an example CUPS parser? Perhaps that parser should be modified as well. Best, |
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 Cheers, |
Updated by lsf37 on 2009-01-31 06:54 UTC
|
Updated by lsf37 on 2009-01-31 13:12 UTC
|
Reported by mcspanky on 2008-07-04 03:26 UTC
The examples/java/java.flex scanner can't handle the integer literal -2147483648, because it treats this as two tokens (a unary minus followed by a positive integer literal), and the second token is not a valid integer literal, it's too big to fit into an int.
This is the same representation problem that causes Math.abs(int) to return negative values when called with Integer.MIN_VALUE.
The text was updated successfully, but these errors were encountered: