[antlr-interest] Problem with AST
Marcin Rzeźnicki
marcin-rzeznicki at wp.pl
Wed Oct 20 12:46:00 PDT 2004
Bryan Ewbank wrote:
> 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.
Thank you very much, it seems that your grammar generates exactly the
same language as mine, in fact I was not aware that you can use "regular
expression" syntax in parser grammars. It seems to be very useful
because it helps to eliminate problematic null productions. I will try
to achieve this in way you have described.
--
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