[antlr-interest] Problem with AST

Marcin Rzeźnicki marcin-rzeznicki at wp.pl
Wed Oct 20 14:37:17 PDT 2004


Marcin Rzeźnicki wrote:
> 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.

Just one more question. I started to think about that idea and I have 
become aware of fact that transformation like these destroys operator 
connectiveness. It seems to me that all operators bind to the left. Is 
there any way to achieve right binding? For example: a OP b OP c ( OP 
stands for binary operator) will become #(OP #(OP a b) c), I would like 
to be able to implement in some cases #(OP a #(OP b c)).
--
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