I've been playing with the Java grammar (
https://github.com/antlr/grammars-v4/blob/master/java/Java.g4#L497) and I've run into a slight problem. The grammar defines IntegerLiterals as positive integers only, and has a unary minus operator. I can use these to parse both "-123" and "-(123)" to -123 just fine. However, when I try to parse "-
2147483648", my integer parsing freaks out because
2147483648 causes an overflow. If I add '-'? to the integer rule, then I seem to run into situations where actual subtractions (e.g. "-2147483647-1") are not parsed correctly (interestingly, "-
2147483647 - 1" is parsed correctly; note the spaces).
I've come up with some workarounds to detect and avoid this, but surely this problem has been encountered before; what are some recommended practices for handling these situations?