[antlr-interest] Re: working with AST

Adrian Sandor aditsu at yahoo.com
Tue Jul 22 13:02:33 PDT 2003


thanks a lot Monty, it worked like a charm! :)
I actually overloaded the match function in the tree parser (to get 
the text of every element) and I was having problems because the 
predicates were matched twice (so their text was output twice)
but now everything is fine :)

Adrian

--- In antlr-interest at yahoogroups.com, mzukowski at y... wrote:
> tokens{
> ALT1;
> ALT2;
> }
> 
> rule1: (test1)=> alt1 {##=#(#[ALT1], ##);}
>        | alt2 {##=#(#[ALT2],##);}
> 
> This is a common idiom.  I use it all over the gcc grammar for 
instance.
> http://www.codetransform.com/gcc.html
> 
> ## means "the current tree"
> #[ALT1] means create a new node with ALT1 as the type
> #() means create a new tree with the nodes given
> 
> Monty
> 
> -----Original Message-----
> From: Adrian Sandor [mailto:aditsu at y...] 
> Sent: Saturday, July 19, 2003 6:36 AM
> To: antlr-interest at yahoogroups.com
> Subject: [antlr-interest] working with AST
> 
> 
> I have a parser which builds an AST, and uses some syntactic 
predicates;
> currently it's basically a list, it doesn't have levels, and when I 
parse
> the AST for translation, I need to use similar predicates for 
correct
> recognition I know I should create subtrees for easier processing, 
but the
> only example I saw was for expressions where it was very easy to 
use the
> operators as roots, but in my case I can't find any specific token 
to
> identify the subtree uniquely is there any way to create and add
> non-existing tokens as roots to mark certain kinds of subtrees?
> 
> e.g. I have:
> rule1: (test1) => alt1 | alt2;
> 
> then I want to "label" the two alternatives, e.g. #(ALT1 alt1) and #
(ALT2
> alt2), where ALT1 and ALT2 did not exist in the lexer can I do 
that? or
> something similar?
> 
> Adrian



 

Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/ 




More information about the antlr-interest mailing list