[antlr-interest] Re: working with AST

mzukowski at yci.com mzukowski at yci.com
Tue Jul 22 13:19:38 PDT 2003


FYI, the inputState.guessing variable tells you whether you are in a
predicate or not, you could look at that to know whether to output text or
not.

Monty

-----Original Message-----
From: Adrian Sandor [mailto:aditsu at yahoo.com] 
Sent: Tuesday, July 22, 2003 1:03 PM
To: antlr-interest at yahoogroups.com
Subject: [antlr-interest] Re: working with AST



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/ 


 

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




More information about the antlr-interest mailing list