[antlr-interest] [v3] Can't seem to resolve through syntactic predicates...

Thomas Brandon tbrandonau at gmail.com
Wed Jun 27 01:17:06 PDT 2007


On 6/27/07, Mark Mandel <mark.mandel at gmail.com> wrote:
> I have the following grammar, that is essnetially:
>
>
> tagInnerValues
>         :
>         (
>         {
>            complicatedPredicate()
>         }?=> tagAttribute*
>         )
>         |
>         (
>         {
>         (
>                 !complicatedPredicate()
>         )
>         }?=> script
>         )
>         |
>         ;
>
> Now, both rules 'tagAttribute', and 'script' use some of the same
> tokens in their rules (the EQUALS token to be exact), so
> understandably, I get the error:
>
> rule tagInnerValues has non-LL(*) decision due to recursive rule
> invocations reachable from alts 1,2,3.  Resolve by left-factoring or
> using syntactic predicates or using backtrack=true option
>
> But, I'm confused in that, I have a syntactic predicate - either
> tagAttributes OR script are going to be required, never both - so why
> am I getting the warning? I would have thought the code above would
> have got rid of it.
>
> Side note - got my ANTLR book in the post today :D very excited.
>
> Mark
>
> --
> E: mark.mandel at gmail.com
> W: www.compoundtheory.com
>
This may not be correct, haven't tested, but you might try specifying
a fixed lookahead. Something like:
tagInnerValues
       :
       (    options {k=1;}:
           { complicatedPredicate() }?=> tagAttribute*
       |
           { !complicatedPredicate() }?=> script
       |
       )
       ;
I had a similar non-LL(*) error, though in a lexer rule not a parser
rule, and while adding predicates hadn't correctly resolved it, adding
a fixed lookahead did. The error message for such problems used to say
"Resolve by left-factoring or using syntactic predicates with fixed k
lookahead or using backtrack=true option" but this was subsequently
changed to only mention predicates, not fixed lookahead. Maybe this
needs to go back.

Tom.


More information about the antlr-interest mailing list