An expression is constructed from literals, identifiers, function calls and operators. An identifier can identify a constant, a variable or (within a subprogram) a formal parameter.
The predefined operators are:
operator | priority | interpretation | left argument | right argument | result |
---|---|---|---|---|---|
! | 5 | monadic not | bit | bit | |
! | 5 | monadic not | byte | byte | |
+ | 5 | monadic plus | byte | byte | |
- | 5 | monadic minus | byte | byte | |
* | 4 | multiplication | byte | byte | byte |
/ | 4 | division | byte | byte | byte |
% | 4 | modulo | byte | byte | byte |
+ | 3 | plus | byte | byte | byte |
- | 3 | minus | byte | byte | byte |
<< | 2 | shift left | byte | byte | byte |
>> | 2 | shift right | byte | byte | byte |
> | 2 | larger than | byte | byte | bit |
< | 2 | less than | byte | byte | bit |
>= | 2 | larger than or equal | byte | byte | bit |
< = | 2 | less than or equal | byte | byte | bit |
== | 2 | equal | byte | byte | bit |
!= | 2 | not equal | byte | byte | bit |
& | 1 | and | bit | bit | bit |
& | 1 | and | byte | byte | byte |
| | 1 | or | bit | bit | bit |
| | 1 | or | byte | byte | byte |
^ | 1 | xor | bit | bit | bit |
^ | 1 | xor | byte | byte | byte |
The operators which are predefined can (for the same arguments) not be redeclared, so these operators have a fixed meaning. Other operators can be declared and redeclared by the user.
All operators which operate on bytes can also operate on universals. When the result from byte arguments is byte, the result from univeral arguments will be universal. When the result from byte arguments is bit, the result from univeral arguments will also be bit.
var byte a = 1 << n
if ( a > b ) | ( c < d ) | ( x != y ) then
x = ( x & 0b_1100_0011 ) | 0b_0001_0100
end if
Braces can be used to force the association, otherwise the operator's associate with their arguments according to operator's priority. For operators of equal priority the leftmost operator gets higher precedence.
var byte x = ! a + b -- is ( ! a ) + b
var y = ! ( a + b ) -- () used to force another interpretation
The order in which independent parts of an expression are evaluated is not defined. A part of an expression might be evaluated more than once, a part which has no influence on the overall value of an expression might not be evaluated at all. Functions with side effects can make this behaviour noticable.
var byte n = 1
function f return byte is
n = n + 1
return 3
end function
function g return byte is
n = 2 * n
return 4
end function
var byte a = f + g
if n == 4 then
-- might be executed, but don't count on it
end if