Right associative operators?
1 posts in topic
Flat View  Flat View

Posted By:   Anonymous
Posted On:   Sunday, February 15, 2004 07:08 PM

How do I make ANTLR generate an AST that associates to the right instead of to the left?

I.e I want to parse something like this (just an example)

a -> b -> c

To a tree that has this structure:

a ->
b c

Generating left-associative trees seems quite easy (using the ^ notation). Is there a similarly easy way to generate the right associative trees as well?

Re: Right associative operators?

Posted By:   Jeffrey_Brown  
Posted On:   Saturday, March 13, 2004 09:50 AM

You need to use tail recursion. Exponentiation, for example...

power : atom (EXP^ power)? ;

(Answer compliments of Ter Parr)
About | Sitemap | Contact