Using both global and local (rule) attribute scopes

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)