Operators
All defined operators are shown in table below. At this time it is not possible to define custom operators but it can change in the future (the system offers it but there is no syntax for it)
Operators are grouped by their precedence, they have equal precedence within each group. If there are two operators in a row the one with lower precedence will be applied first (the left operator will use precedence number but right one will use active precedence number). If they have same precedence their associativity will determine if left or right one will be applied first. If you are not sure about precedence use parenthesis in expression to force execution order.
Defined operators
Syntax | Arity | Assoc | Precedence (active) | |
---|---|---|---|---|
Precedence group 100 | ||||
^ | binary | right | 100 (100) | Power operator. |
Precedence group 150 | ||||
+ | unary | left | 150 (50) | Unary plus operator — the most important operator ;) |
- | unary | left | 150 (50) | Unary minus operator. |
! | unary | left | 150 (50) | Unary not operator. Returns zero if applied on non-zero number, returns one if applied on zero. |
Precedence group 200 | ||||
* | binary | left | 200 (220) | Multiply operator. |
/ | binary | left | 200 (220) | Division operator. |
\ | binary | left | 200 (220) | Integer division operator. Divides given numbers and returns integer part of the result. |
% | binary | left | 200 (220) | Module operator. Returns remainder of integer division. |
Precedence group 300 | ||||
+ | binary | left | 300 (320) | Add operator. |
- | binary | left | 300 (320) | Subtract operator. |
Precedence group 400 | ||||
< | binary | left | 400 (420) | Less-than operator. Returns one if left operand is less than right operand, zero otherwise. |
> | binary | left | 400 (420) | Greater-than operator. Returns one if left operand is greater than right operand, zero otherwise. |
<= | binary | left | 400 (420) | Less-than-or-equal operator. Returns one if left operand is less than or equal right operand, zero otherwise. |
>= | binary | left | 400 (420) | Greater-than-or-equal operator. Returns one if left operand is greater than or equal right operand, zero otherwise. |
Precedence group 500 | ||||
== | binary | left | 500 (520) | Equals operator. Returns one if left and right operands are equal, zero otherwise. |
!= | binary | left | 500 (520) | Equals operator. Returns zero if left and right operands are equal, one otherwise. |
&& | binary | left | 500 (520) | Logical-and operator. Returns one if both left and right operands non-zero, zero otherwise. |
Precedence group 600 | ||||
^^ | binary | left | 600 (620) | Logical-or operator. Returns one if just one of operands is non-zero, zero otherwise. |
Precedence group 700 | ||||
|| | binary | left | 700 (720) | Logical-or operator. Returns one if at least one of operands are non-zero, zero otherwise. |
Examples
Input
1 2 3 4 5 | // - is left associative let a = 2 - 2 - 2; let a' = (2 - 2) - 2; let a'' = 2 - (2 - 2); process Constants with ConstantDumper; |
Output
a = -2; a' = -2; a'' = 2;
Input
1 2 3 4 5 | // ^ (power) is right associative let b = 2 ^ 2 ^ 3; let b' = 2 ^ (2 ^ 3); let b'' = (2 ^ 2) ^ 3; process Constants with ConstantDumper; |
Output
b = 256; b' = 256; b'' = 64;
Input
1 2 3 4 5 | // power have lower active precedence than minus let c = -2^2; let c' = -(2^2); let c'' = (-2)^2; process Constants with ConstantDumper; |
Output
c = -4; c' = -4; c'' = 4;