[antlr-interest] Problem with generated code

Mark Wright markwright at internode.on.net
Tue Feb 12 21:05:32 PST 2008


> 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.

Regards, Mark

-- 


More information about the antlr-interest mailing list