[antlr-interest] Java.g grammar issues & potential fix
David Ewing
dewing at apple.com
Thu Apr 8 10:22:03 PDT 2004
Now that you remind me. The 1.4 Java grammar also includes generics, so
shouldn't we call it 1.5? Of course, it is missing a number of other
Java 1.5 language features, metadata being one of the more interesting
ones. Is anybody working on adding this support?
Dave
On Apr 7, 2004, at 2:10 AM, Vincent Mallet wrote:
> Terence & All,
>
> A problem in Clover (code coverage for Java which uses antlr)
> prompted me to look at the java.g "1.4 update" grammar and I found
> a few problems with the lexer:
> 1. the grammar won't accept octal-looking floats or doubles
> (09d for example)
> 2. the grammar will accept hexadecimal numbers with a fractional
> part (0x12.34 for example)
>
> I have seen a fix for problem #1 in java.g version 1.21-october-2003
> but #2 is definitely broken.
>
> In an attempt to clarify that part of the grammar I came up with a
> version of the NUM_INT lexer rule which seems to be more correct and
> potentially easier to read (indentation might need some work).
>
> If you have an opinion on the new rule I would love to hear it.
>
> Here it goes:
> take java.g, truncate evertyhing after "NUM_INT", replace with:
>
>
> ---cut-cut---
> // a numeric literal
> NUM_INT
> : // all floating point literals with a whole-number part
> ( (DIGIT)+ ('.' | 'e' | 'E' | 'f' | 'F' | 'd' | 'D' ) )=>
> (DIGIT)+
> ( (('.' (DIGIT)* (EXPONENT)? | EXPONENT )
> (('f'|'F') { _ttype = NUM_FLOAT; } | ('d' | 'D')? {
> _ttype = NUM_DOUBLE; } )
> )
> | ( ('f'|'F') { _ttype = NUM_FLOAT; } )
> | ( ('d'|'D') { _ttype = NUM_DOUBLE; } )
> )
>
> | // all floating point literals with no whole-number part
> (possibly just '.')
> '.' { _ttype = DOT; }
> (DIGIT)+ (EXPONENT)?
> ( ('f'|'F') { _ttype = NUM_FLOAT; } | ('d' | 'D')? { _ttype
> = NUM_DOUBLE; } )
>
> | // all decimal literals
> ( '0' ('0'..'7')+ // octal
> | ('1'..'9') (DIGIT)+ // decimal
> | '0' ('x' | 'X') (HEX_DIGIT)+ // hexa
> | '0' // decimal
> )
> (('l' | 'L') { _ttype = NUM_LONG; })?
> ;
>
>
> // a couple protected methods to assist in matching floating point
> numbers
> protected
> DIGIT
> : '0'..'9'
> ;
>
> protected
> EXPONENT
> : ('e'|'E') ('+'|'-')? ('0'..'9')+
> ;
>
> ---cut-cut---
>
> Thanks,
>
> Vince.
>
>
>
>
>
>
>
>
>
> Yahoo! Groups Links
>
>
>
>
>
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/antlr-interest/
<*> To unsubscribe from this group, send an email to:
antlr-interest-unsubscribe at yahoogroups.com
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/
More information about the antlr-interest
mailing list