> Tree Grammar Output =  {vs{vs} }

What's happening is that you are essentially synthesizing a complex string 
template
containing multiple <v>'s.  This gets evaluated eventually in main(),
which is why you see {vs {vs}}.  Instead, force the substitution
before returning a new template.  So your tree grammar will look like this:

tree grammar blockTree;

options {
  language = Java;
  output = template;
  tokenVocab = block;
  ASTLabelType = CommonTree;
}

@header {
//  package tg_bug;
}

rule: ^(BLOCK (vstring += v)* (sstring+=s)* ENDBLOCK) ->
      template(a={$BLOCK.text}, v={$vstring}, s={$sstring}, 
b={$ENDBLOCK.text})
<< <a><v><s><b> >>
;

v: 'v' -> template() "v";

s: 's' -> template() "s"
 | x=rule ->
      template(r={$x.st.toString()})
 << <r> >>
;

(I took the liberty to change the style of the template spec for "s", and I 
commented out
the 'package tg_bug' decl's to get this thing to compile and run for me. 
Packages-sigh.)
The key change is the template spec for the production "s->rule".  The 
"toString()" forces the
evaluation of the s.t. before creating a new one.

> However if I re-write the grammar as below, I don't have this problem.
>
> b->'{' '}'
>  | '{' v '}'
>  | '{' s '}'
>  | '{' v+ s+ '}'

Not sure which grammar you're referring to b/c there is a parse grammar and
a tree grammar.  Don't do this.  That's not the problem, and it looks ugly.

> RTFM

Reading never really helps. Always better to just debug the friggin' code 
and figure
out what it is doing.

Ken


 


List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe: 
http://www.antlr.org/mailman/options/antlr-interest/your-email-address

-- 
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.

Reply via email to