Sfairadora

  • Reference Guide

Priority of Operators

If a complex expression is written, ambiguity in the order of operator evaluation can arise. For instance, the expression 1 + 2 * 3 could be understood as (1 + 2) * 3 or 1 + (2 * 3). In general, if two operators – one from the left and the other from the right – are applied to a single sub-expression, it is necessary to decide which of the two operators is to be applied first. To solve this problem, Enki employs the usual approach of assigning priorities to the operators. The problem of operator priority does not arise with all the operators, but only with those that have a parameter specified as their leftmost or rightmost syntactic element. If an operator contains a sub-expression as its leftmost syntactic element, it is called left-open. Analogously, a right-open operator is defined. Hence, only to open operators a priority must be assigned. If an operator is both left-open and right-open, it follows, that two priorities – a left one and a right one – should be assigned. By assigning two priorities, also the operator associativity problem is solved (i.e., for instance, the expression x / y / z should be understood as (x / y) / z, while x ** y ** z should be understood as x ** (y ** z)). If an operator should be left associative, it is necessary to set a higher left priority to it, while for a right associative operator the opposite.
The following table summarizes the priorities of all the open operators. The priority is enclosed in braces. The lower value, the higher priority.
@<21>
<30>[n]
<30> . <29>
<30> [*]
<50> sec
<50> days
<50> day
<50> min
<50> deg
<50> inch
<50> hr
<80> ** <79>
& <81>
* <81>
<100> ++
<100> --
++ <101>
-- <101>
- <101>
! <101>
~ <101>
[typ] <111>
<130> * <129>
<130> / <129>
<130> div <129>
<130> % <129>
<130> mod <129>
<140> + <139>
<140> - <139>
<140> # <str> <139>
<140> # <139>
<150> rotr <149>
<150> shr <149>
<150> shl <149>
<150> rotl <149>
<170> == <169>
<170> != <169>
<170> === <169>
<170> !== <169>
<170> > <169>
<170> >= <169>
<170> < <169>
<170> <= <169>
<190> & <189>
<210> ^ <209>
<230> | <229>
<240> ? blok : <241>
<240> ? <241>
<250> <- fn(x, ...)
<260> = <261>
<260> += <261>
<260> -= <261>
<260> *= <261>
<260> /= <261>
<260> **= <261>
<260> #= <261>
<260> # <str>= <261>
<260> |= <261>
&var = <261>
def name = <271>
var Type name = <271>
wait_for_change(...) <271>
wait_until(...) <271>
if(cond) <291>
if(cond) block else <291>
while(cond) <291>
while(cond) block until(cond) block else <291>
for(...) <291>
for(...) block until(cond) block else <291>
break <291>
return <291>
try <291>
try block else <291>
<300>;
<300>; <299>