The following table shows all operators supported by PCC2. Operators have a certain precedence or binding strength, which determines which parts of the expression belong to that operator. For example, in 2 + 3 * 4, the precedence of * is higher than the precedence of +, so the multiplication is performed first. The addition then adds 2 and the result of 3 * 4. The table shows operators in increasing order of precedence, i.e. later operators are evaluated before those shown first.
(1) | a; b | Sequence: evaluate a, discard its result, then evaluate b. This is needed very rarely, but can be useful to perform an assignment before producing the actual value in a search expression, for example. |
(2) | a := b | Assignment: evaluate b, and assign it to a. Returns b. |
(3) | a Or b | Logical Or: return True if either operand is True. If the result is known after evaluating a (i.e. a is True), does not evaluate b (short-circuit evaluation). |
a Xor b | Logical Exclusive-Or: return True if one operand is True and one is False. If the result is known after evaluating a (i.e. a is EMPTY), does not evaluate b (short-circuit evaluation). | |
(4) | a And b | Logical And: return False if either operand is False. If the result is known after evaluating a (i.e. a is False), does not evaluate b (short-circuit evaluation). |
(5) | Not a | Logical Not: return True if operand is False, False if operand is True. |
(6) | a = b | Comparison: return True if a is identical to b. Values must have comparable types; when you attempt to compare a number and a string, this will generate an error. |
a <> b | Comparison: return True if a is different from b. Note that values still must have comparable types. | |
a < b | Comparison: return True if a is less than b. | |
a > b | Comparison: return True if a is greater than b. | |
a <= b | Comparison: return True if a less or equal to b. | |
a >= b | Comparison: return True if a is greater or equal to b. | |
(7) | a # b | Concatenation: convert a and b to strings and concatenate them. |
a & b | Concatenation: convert a and b to strings and concatenate them. If either is EMPTY but the other is not, treat the EMPTY one as empty string. | |
(8) | a + b | Addition: add a and b, which may be numbers or strings. |
a - b | Subtraction: subtract b from a, which must both be numbers. | |
(9) | a * b | Multiplication: multiply a and b, which must both be numbers. |
a / b | Division: divide a by b, which must both be numbers. | |
a \ b | Integer division: divide a by b, which must both be integers, and discard the remainder. | |
a Mod b | Integer remainder: divide a by b and return the remainder. Both operands must be integers. | |
(10) | -a | Negation: change sign of a, which must be a number. |
+a | Unary plus: do not change sign of a, which must be a number. Exists for symmetry with "-". | |
(11) | a ^ b | Power: compute a-to-the-bth. Both operands must be numbers. |
Operands
Operands to operators are shown as "a" and "b" above. The following things are possible operands:
- literals.
- an expression of higher precedence, as shown in the multiplication/addition example above the table.
- an expression within parentheses.
- a function call.
- a variable or property.