[antlr-interest] Bug in java grammar 1.18

John P N Pybus john-yahoo at pybus.org
Mon Jan 14 08:18:47 PST 2002


While we're on the subject of java.g.  The patch I posted on 12th November to 
fix the identification of float, and double constants hasn't been applied yet.

Here's what I sent previously:

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#23078
 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;
 }
 }
 
======
 
(It's cut and pasted from the yahoo groups page so the patch may be slightly 
mangled, but it should be easy to make the change by hand.)

John Pybus

 

Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/ 



More information about the antlr-interest mailing list