[antlr-interest] Bug in Java 1.3 grammer
john-yahoo at pybus.org
john-yahoo at pybus.org
Mon Nov 12 03:48:19 PST 2001
Hi,
I'm updating an application which used the java 1.2 grammer in antlr
2.7.1 to use the 1.3 grammer from
<http://www.antlr.org/grammars/java>.
It's good that the new grammer distiguishes NUM_FLOAT from
NUM_DOUBLE. It would be even better if it got it right ;-).
Your grammer parses 3.14F as a float, 3.14 also as a float, and
3.14D as a double. According to the java langspec:
http://java.sun.com/docs/books/jls/second_edition/html/lexical.doc.html#230798
in the case with no suffix it should be a double.
The fix is dead easy:
--- java.g Mon Nov 12 11:37:07 2001
+++ java.g.fixed Mon Nov 12 11:38:41 2001
@@ -1170,9 +1170,9 @@
( ('0'..'9')+ (EXPONENT)? (f1:FLOAT_SUFFIX {t=f1;})?
{
- if (t != null &&
t.getText().toUpperCase().indexOf('D')>=0) {
- _ttype = NUM_DOUBLE;
+ if (t != null &&
t.getText().toUpperCase().indexOf('F')>=0) {
+ _ttype = NUM_FLOAT;
}
else {
- _ttype = NUM_FLOAT;
+ _ttype = NUM_DOUBLE;
}
}
@@ -1205,9 +1205,9 @@
)
{
- if (t != null && t.getText().toUpperCase()
.indexOf('D') >= 0) {
- _ttype = NUM_DOUBLE;
+ if (t != null &&
t.getText().toUpperCase().indexOf('F') >= 0) {
+ _ttype = NUM_FLOAT;
}
else {
- _ttype = NUM_FLOAT;
+ _ttype = NUM_DOUBLE;
}
}
======
(The Yahoo Web interface may well have mangled that but you get the
idea.)
Thanks for the all the efforts in producing the grammer it's much
appreciated, antlr is a fantastic thing.
John Pybus
Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
More information about the antlr-interest
mailing list