[antlr-interest] Warning(200) for k=1
Gavin Lambert
antlr at mirality.co.nz
Sat Jun 14 21:48:22 PDT 2008
At 12:10 15/06/2008, Aurelian Melinte wrote:
>I am forced to use k=1 for a large C++ grammar - while the
grammar
>has been designed for k=2, Antlr 3.0.1 will run out of memory
for
>anything else but k=1. I
I'd start by fixing up your lexer. And write some unit tests for
it.
>OCTALINT
> :
> '0' ('0'..'7')* (IntegerSuffix)?
> ;
>
>HEXADECIMALINT
> :
> '0' ('x' | 'X') (HexadecimalDigit)+ (IntegerSuffix)?
> ;
>
>FLOATONE
> :
> ( (Digit)+ ('.' | 'e' | 'E') )=>
> (Digit)+
> ( '.' (Digit)* (Exponent)?
> | Exponent // should be FLOATTWO?
> )
> ;
>
>FLOATTWO
> :
> '.' (Digit)+ (Exponent)? (FloatSuffix)?
> ;
At k=1 (and when encountering loops, the lexer always behaves like
it's k=1), these rules are mutually ambiguous. You should merge
them into a single rule with appropriate lookahead disambiguation.
Remember, predicates don't choose between rules, they choose
between alts within a rule. Or that's how they seem to behave in
the lexer, at least.
>IntegerSuffix
> :
> LongSuffix (UnsignedSuffix)
> UnsignedSuffix (LongSuffix)
> ;
>
>FloatSuffix
> :
> ('f' | 'F' | 'l' | 'L' )
> ;
Surely these should be fragments?
More information about the antlr-interest
mailing list