[antlr-interest] Using global and dynamic scopes together - is it possible?

Douglas Godfrey douglasgodfrey at gmail.com
Thu Feb 24 07:54:29 PST 2011


you can define local [non-class] variables with the @init clause.
class variables cannot be used because you will get a compile error in the
generated code.

rulename
scope GlobalOne;
@init
{
       bool localFlag;

       $GlobalOne::globalVariable = ....;
       ...
       localFlag = true;
}

On Tue, Feb 22, 2011 at 2:02 PM, Iron Bug <death.iron.bug at gmail.com> wrote:

> Greetings.
> I've been using ANTLR with C interface for a long time and it was ok,
> but today I bumped into a problem:
> I use global scope for certain rules and I sometimes use dynamic scopes
> for minor local variables. And in one rule it happened the different
> scopes have met each other.
> Something like:
>
> rulename
> scope GlobalOne;
> scope
> {
>        bool localFlag;
> }
> @init
> {
>        $GlobalOne::globalVariable = ....;
>        ...
>        $rulename::localFlag = true;
> }
>
> And ANTLR does not eat that. Well, I'm not sure it's possible even.
> Maybe I should use some different syntax? I tried some variants that
> seemed reasonable to me, but failed.
> I don't know whether it is a problem of ANTLR itself or of the C
> interface realization.
> Can I use both variants of scopes in one rule?
>
> I use ANTLR 3.3 with the latest shapshot version of the C interface
> (libantlr3c-3.3-SNAPSHOT).
>
> Just in case, the errors generated are like:
>
> unexpected token: bool localFlag;
>
> syntax error: expecting SEMI, found '@'
>
> unknown dynamic scope: rulename
>
>
> 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