[antlr-interest] working with AST
mzukowski at yci.com
mzukowski at yci.com
Mon Jul 21 08:29:18 PDT 2003
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 yahoo.com]
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