[antlr-interest] Q: How do I left-factor this?

Austin Hastings Austin_Hastings at Yahoo.com
Mon Nov 19 21:30:29 PST 2007


Gavin,

This was the right direction. Thanks for pointing it out.

=Austin

Gavin Lambert wrote:
> 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