Operators

Operators perform operations on variables and return a result.

Pollen has the standard set of arithmetic and logical operators (shared with C) and adds a few assignment operators of its own.

Category Operators
Arithemetic + - * / %
Relational > >= < <= == != && ||
Increment and Decrement ++ --
Bitwise & | ^
Assignment = += -= *= /= %= &= ^= |= <<= >>= := @=
Ternary ? :

Binding Operator

The first Pollen specific assignment operator is :=. It is used to bind a protocol member to a module which implements the protocol. It is called the binding operator. (More information on the binding operator found here.)

GlobalInterruptsProtocol GI := Mcu.GlobalInterrupts       // bind a protocol member 

Pegging Operator

The second unique Pollen assignment operator is @= and this is used to peg class references to byte arrays. This allows allocating a target class object by overlaying its definition onto an index of a byte array. The byte array at that index must contain a valid instance of the class object. It is called the pegging operator. (More information on the pegging operator found here.)

Class1 cref @= array1                // peg object to array

Pollen has the same operator precedence as C. Here is a table of operator precedence. Operators with higher precedence are evaluated before operators with relatively lower precedence. Operators on the same line have equal precedence. When operators of equal precedence appear in the same expression, a rule must govern which is evaluated first. All binary operators except for the assignment operators are evaluated from left to right; assignment operators are evaluated right to left.

Operators Precedence
Postfix expr++ expr--
Unary ++expr --expr +expr -expr ~ !
Multiplicative * / %
Additive + -
Bit shift << >>
Relational < > <= >=
Equality == !=
Bitwise AND &
Bitwise exclusive OR ^
Bitwise inclusive OR |
Logical AND &&
Logical OR ||
Ternary ? :
Assignment = += -= *= /= %= &= ^= |= <<= >>= @= :=