Here is my initial implementation templates for @scopeinit and
@scopeafter in the Java target:
attributeScope(scope) ::= <<
<if(scope.attributes)>
protected static class <scope.name>_scope {
<if(scope.actions.scopeinit)>
public <scope.name>_scope() {
<scope.actions.scopeinit>
}
<endif>
<if(scope.actions.scopeafter)>
final void cleanUpScope() {
<scope.actions.scopeafter>
}
<endif>
public static void pushScope( <scope.grammar.recognizerName> grammar
) {
grammar.<scope.name>_stack.push(new <scope.name>_scope());
}
public static void popScope( <scope.grammar.recognizerName> grammar
) {
grammar.<scope.name>_stack.pop()<if(scope.actions.scopeafter)>.cleanUpSc
ope()<endif>;
}
<scope.attributes:{<it.decl>;}; separator="\n">
}
protected Stack <scope.name>_stack = new Stack();<\n>
<endif>
>>
globalAttributeScope(scope) ::= <<
<attributeScope(...)>
>>
ruleAttributeScope(scope) ::= <<
<attributeScope(...)>
>>
// Many items skipped here...
ruleScopeSetUp() ::= <<
<ruleDescriptor.useScopes:{<it>_scope.pushScope(this);}; separator="\n">
<ruleDescriptor.ruleScope:{<it.name>_scope.pushScope(this);};
separator="\n">
>>
ruleScopeCleanUp() ::= <<
<ruleDescriptor.useScopes:{<it>_scope.popScope(this);}; separator="\n">
<ruleDescriptor.ruleScope:{<it.name>_scope.popScope(this);};
separator="\n">
>>
Sam
From: Sam Harwell
Sent: Thursday, January 22, 2009 12:08 PM
To: [email protected]
Subject: RE: [antlr-dev] @init for global scopes?
Maybe @scopeinit{...} is better?
_______________________________________________
antlr-dev mailing list
[email protected]
http://www.antlr.org/mailman/listinfo/antlr-dev