[antlr-interest] Q: How do I left-factor this?
Gavin Lambert
antlr at mirality.co.nz
Tue Nov 13 22:56:15 PST 2007
At 00:01 14/11/2007, Austin Hastings wrote:
>fragment MultiLineComment : '/*' .* '*/';
>fragment SingleLineComment : '//' ~('\r' | '\n')* '\r'? '\n';
>fragment NestedCodeBlock
> : '{'
> (options {greedy=false;}
> : MultiLineComment
> | NestedCodeBlock
> | SingleLineComment
> | QUOTED_LITERAL
> | .
> )*
> '}'
> ;
>
>The problem is that ANTLR complains about non-LL(*) left
recursion
>in alternatives 1,2 and 5, and suggests left factoring the
things.
>I have found that adding option k=2 will make the problem
>(apparently) go away.
The only thing I can see in there that looks particularly dodgy is
the final "." alt. Try changing it to "~('{' | '}')" and see if
that improves anything.
More information about the antlr-interest
mailing list