[antlr-interest] Problem with AST
Bryan Ewbank
ewbank at synopsys.com
Wed Oct 20 02:04:38 PDT 2004
Yes, you can do what you are asking - the syntax I use is a bit different,
but accomplishes
the same results...
For example, you use this:
> andexp : notexp andexp_part;
> andexp_part : AND notexp andexp_part |
> ;
It is more concise, in ANTLR, to use this instead:
andexp : notexp ( AND^ notexp)* ;
// andexp is notexpr followed by zero or more sequences of AND notexpr
Here, the "^" after the AND means "make AND the root of the tree so far",
but only
if an AND is seen. The "( .. )*" means "zero or more times", which
accomplishes
the same thing as your <andexp_part> production.
Therefore, the extra node is added only when it is required, otherwise the
tree produced by <notexp> is forwarded unchanged, as per your requirements.
> Considering for example
> 'andexp' production: if andexp_aprt is not epsilon-production then
> resutling tree should be #(AND notexp "andexp_part without AND node"),
> otherwise just #notexp. And so on. How this coulbe be achieved? Thank
> you in advance
> --
> Greetings
> Marcin Rzeźnicki
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