Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 3 Current »

It is possible to use both global and local (rule-level) scopes together in ANTLR v3 but you have to get the order right: global scopes come after local scope but before @init.

grammar T;

scope GlobalOne {
    int foo;
}

myrule
scope {
    int bar;
}
scope GlobalOne;
@init {
    /* your stuff here */
}
    : case1
    | case2
    ;

To use more than one global scope, specify them in a comma-delimited list:

myrule
scope {
    int foo;
}
scope GlobalOne, GlobalTwo, GlobalThree;

(Adapted from mailing list post by Jim Idle)

  • No labels