[antlr-interest] nesting rules, getting rule text
    Robin Debreuil 
    robin at debreuil.com
       
    Thu Mar  4 01:08:11 PST 2004
    
    
  
Hi again, two hopefully easy questions (that is - hard for me, easy for you
: ).
1) I can't seem to figure out how to nest rules... I'm using a hetrogeneous
tree, and would like rules like (DOT identifier)* to nest. So something
like:
ruleA
 : ruleB (DOT! ruleB)*
 ;
becomes the tree:
AST_B
     |
     AST_B
              |
              AST_B
Maybe it would be easier to explain right by posting the type of thing I've
been trying, something like:
ruleA!
 :   r1:ruleB
  ( r2:ruleB {#r1 = #(#r1, #r2);} )*
 {#ruleA = #r1;}
 ;
which nests, but turns a.b.c into #(a, c). I'm doing this in the parser, not
the tree walker.
2) When getting the text of a rule, I've been calling the generated
variables directly (xx_AST), as in:
ruleA!
 : id:identifier STAR!
  { #ruleA =    #( [Ident, id_AST.getText()] ); } // eg. "id_AST"
 ;
Is there a better way to do that? Ident in this case is a user defined AST
token if that makes a difference, as in:
tokens
{
    Ident      <AST=DDW.CSharp.Ident>;
}
Thanks for the help again : ). The C# parser is all running and put into
trees, but the trees need a lot of work in the expression area - like array
declarations etc. I'm kind of not getting some of the required syntax there
I'm afraid...
Cheers, and thanks as always : )
Robin
 
Yahoo! Groups Links
<*> To visit your group on the web, go to:
     http://groups.yahoo.com/group/antlr-interest/
<*> To unsubscribe from this group, send an email to:
     antlr-interest-unsubscribe at yahoogroups.com
<*> Your use of Yahoo! Groups is subject to:
     http://docs.yahoo.com/info/terms/
 
    
    
More information about the antlr-interest
mailing list