Precedence and Parentheses

At this point, you may ask yourself, what happens when you mix infix operators like , and ;? For example, does a,b;c mean a,(b;c) or does it mean (a,b);c?

The answer is that each built-in operator has a defined precedence value, which determines the meaning of such expressions. An operator with a lower value “binds harder” than an operator with a higher value. The Flora manual has a table of operators and their precedence levels. Unfortunately, this table is incomplete. The authoritative reference is the Flora source code, in particular flroperator.P, which uses constants defined in flrincludes/flora_terms.flh.

To answer the question above, we find these lines in flora_terms.flh:

#define FL_AND_CONNECTIVE ','
#define FL_OR_CONNECTIVE ';'

and in flroperator.P:

flora_op(1400,xfy,FL_AND_CONNECTIVE).
flora_op(1500,xfy,FL_OR_CONNECTIVE).

The first argument to flora_op is the precedence value. So , has a lower precedence value than ;. In other words, it “binds stronger”. Therefore, the correct reading of the expression above is (a,b);c.

In most cases, you don’t have to worry about the operator precedences, as they tend to “do the right thing”. But suppose you wanted to express a,(b;c). The solution then is to simply add parentheses, just as shown. Parentheses bind stronger than any operator, and can be added around any Flora expression. If in doubt, add parentheses to force the meaning you intend.

For a complete reference of operator precedence in Sunflower, please consult the Flora-2 Manual [1].

[1]Kifer, Michael, Guizhen Yang, Wan Hui, and Chang Zhao. 2014. Flora-2: User’s Manual. 1.0. Stony Brook University, Stony Brook: Department of Computer Science.