[antlr-interest] Previous rule element reference in a scope

Jim Idle jimi at temporal-wave.com
Wed Apr 13 17:51:09 PDT 2011


In the WITH node, when you walk the tree, you can have a scope and set the
node of the WITH subject in to the scope, then you refer to it in the
scope when you walk the tree and find a . node that has no LHS.

Don't try to rewrite it as that isn't the way to do it.

Jim

> -----Original Message-----
> From: antlr-interest-bounces at antlr.org [mailto:antlr-interest-
> bounces at antlr.org] On Behalf Of Graham Mer
> Sent: Wednesday, April 13, 2011 5:37 PM
> To: antlr-interest at antlr.org
> Subject: Re: [antlr-interest] Previous rule element reference in a
> scope
>
> > It's not clear from your question if only method calls are legal
> > within a "with" statement, in which case the suggestions made should
> > work, or if (as I suspect) any statement is legal within a "with",
> like in javascript.
>
> Thanks for the replies, everyone.
>
> You're correct, Peter, it is not limited to only method calls. I don't
> think parameter passing will work, since the enclosed statement block
> is not part of the withStatement rule. I (over-?) simplified my example
> grammar fragment as an illustration; withStatement and the stuff inside
> the With block are all "statements" in higher rules, so I'd need to
> pass parameters among large numbers of rules, which is doesn't seem
> very maintainable. Isn't this exactly what a scope was intended for?
>
> Assuming this is an appropriate place to use a scope, how do I get that
> withStatement ID value into a scope instead of into a parameter?
>
> Thanks again!
>
> List: http://www.antlr.org/mailman/listinfo/antlr-interest
> Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-
> email-address


More information about the antlr-interest mailing list