This project has moved and is read-only. For the latest updates, please go here.

Operator and with multiple arguments

Jan 14, 2014 at 7:44 AM

I want to realize grammar for expression like this:
A and B and C and D or Z
If I use general recommendation about binary operations I got
(((A and B) AND C) AND D) or Z
Actually I need a way to treat sequence of "AND" like multiple argument function
AND(A,B,C,D) or Z
Any ideas?
Jan 14, 2014 at 6:40 PM
try defining AND operator as List (with MakePlusRule) and 'AND' as delimiter. But then you might have problem with a single identifier - the parser may try to interpret it as AND-list with a single element.
Alternative is to parse as you have now, and then transform the result parse tree using a tree visitor - I would recommend doing this
Jan 15, 2014 at 5:54 AM
Hi. I tried to MakePlusRule but it has lot's of side effects.
So I think that AST transformation is a good options. Could you please point me to any example?
Jan 22, 2014 at 6:45 PM
I would recommend transforming parse tree, not AST tree. Examples - do not have any, just build a tree visitor/rewriter, that finds certain node patterns (nested AND expressions) and replaces them with a combined node representing AND function over multiple arguments.