On Thu, 2008-09-18 at 16:00 +0200, Dominique de Waleffe wrote:
> I am exploring the use of tree grammars...
>
> I exepcted to be able to write something like the following:
>
> tree grammar PipelineWalker;
>
> options {
> language = Java;
> tokenVocab=Pipeline;
> ASTLabelType=CommonTree;
> }
> @header{
> // import Pipeline;
> }
> pipeline[Pipeline p]: ^(PIPE header body) ;
>
> header : ^('pipeline' name) {
> System.out.println($pipeline::p.getName());
> $pipeline::p.setName($name.text);}
> ;
>
> Where the intent is to get my 'Pipeline' object from the top level and
> modifying it while going down the tree.
>
>
> The problem is that the references I make to $pipeline::p in my header rule
> seem to go untranslated into the generated code:
>
>
You need to use a scope to do this;
pipeline [Pipeline pIn]
scope {
Pipeline p;
}
@init
{
$pipeline::p = $pIn;
}
Then make sure that everything starts with the pipeline rule.
However, I think a better way is:
@members {
protected Pipeline p;
public void setPipeline(Pipeline p) { this.p = p; }
public Pipeline getPipeline() { return this.p; }
}
Then just use p directly in your actions code. After you create the tree
parser, call setPipeline(myPipeline) on it; then invoke the walker. I
suggest a better name than just 'p' though ;-)
Jim
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"il-antlr-interest" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/il-antlr-interest?hl=en
-~----------~----~----~----~------~----~------~--~---
List: http://www.antlr.org:8080/mailman/listinfo/antlr-interest
Unsubscribe:
http://www.antlr.org:8080/mailman/options/antlr-interest/your-email-address