# Treetop equal precedence

How do I make two rules with equal precedence. The obvious example is
true||false&&false
should return false because the true||false is evaluated first, then
&&false.
but also
true&&false||true
should return true because true&&false is false, but then the ||true is
evaluated.

[email protected] wrote:

[Note: parts of this message were removed to make it a legal post.]

How do I make two rules with equal precedence. The obvious example is
true||false&&false
should return false because the true||false is evaluated first, then &&false.
but also
true&&false||true
should return true because true&&false is false, but then the ||true is evaluated.

I don’t understand how your example relates to the way you worded your
question,
but if you have two or more operators at the same level of precedence,
just use
a sequence. For example, a sum of 1 or more terms can be expressed as:

rule sum
term ( (‘+’/‘-’) term )*
end

(with white-space skipping stripped out). If you want to evaluate the
result,
say by providing and calling a value() method, here’s the idiom I use:

‘+’ { def operate(a, b); a+b; end }
/ ‘-’ { def operate(a, b); a-b; end }
end

rule sum