[antlr-interest] Problem with generated code

Thomas Brandon tbrandonau at gmail.com
Tue Feb 12 21:58:33 PST 2008


On Feb 13, 2008 4:05 PM, Mark Wright <markwright at internode.on.net> wrote:
> > So my question is,
> > why is the first action in this rule being brought up, even though it
> > has a dependency on the parameter passed to the rule?
>
> Hello Jamie,
>
> Because its a dis-ambiguating semantic predicate, ANTLR will hoist
> these into rules where it needs them to resolving ambiguities.
> Also ANTLR is likely to call it multiple times.
>
> > Is there a way to avoid this behaviour?
> >
> > Thanks,
> > Jamie Penney
> >
>
> No.  You will need to write the dis-ambiguating semantic predicate
> so that it obtains the information it needs from:
>
> - scanning looking at tokens, usually forwards, but sometimes
> I add a symbol with some information to a token and then look
> backwards for it.
>
> - looking up stuff in a symbol table.
>
> - or you could look in an ANTLR scope that is active everywhere the
> the dis-ambiguating semantic predicate could be hoisted to.

This is a problem with that method of handling contextual keywords. I
would use one of the other methods of handling this that do not cause
such problems (see the wiki entry).

Tom.
>
> Regards, Mark
>
> --
>


More information about the antlr-interest mailing list