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.
Code Block |
---|
grammar |
...
Code Block |
---|
T; scope GlobalOne { int cfoo; } myrule scope { int bool localFlagbar; } scope GlobalOne; @init { /* your stuff here */ } : case1 | case2 ; |
To use more than one global scope, specify them in a comma-delimited list:
Code Block |
---|
myrule
scope {
int foo;
}
scope GlobalOne, GlobalTwo, GlobalThree;
|
(Adapted from mailing list post by Jim Idle)