Precedence rules specify the order in which parts of an expression are parsed, in absence of parenthesis.
For example, in 1 + 2 * 3
, Orc's precedence rules prescribe that the multiplication be parsed as a sub-expression of the addition.
Operators or combinators listed in the table below with higher precedence will be parsed in preference to lower precedence operations or combinators.
Fixity specifies the relative position of an operator and it operands.
For example, +
is infix, so the +
operator is written in between its operands.
However, ?
is postfix, so it is written after its operand.
Associativity specifies the grouping of a series of infix operator (or combinator) expressions, in absence of parenthesis.
For example, division is left associative, so 40 / 4 / 2
is grouped as (40 / 4) / 2
which is 5. It is not 40 / (4 / 2)
= 20.
Similarly, the sequential combinator is right associative, so e >x> f >y> g
is equivalent to e >x> (f >y> g)
.
Table 10.1. Orc Combinator/Operator Precedence, Fixity, and Associativity
Precedence Level | Name | Symbol | Fixity | Associativity |
---|---|---|---|---|
13 | Call | () | Postfix | -- |
Dot Access | . | Postfix | -- | |
Dereference | ? | Postfix | -- | |
12 | Arithmetic Negation | - | Prefix | -- |
Negation (Logical Complement) | ~ | Prefix | -- | |
11 | Exponentiation | ** | Infix | Right |
10 | Multiplication | * | Infix | Left |
Division | / | Infix | Left | |
Modulus | % | Infix | Left | |
9 | Addition/Concatenation | + | Infix | Left |
Subtraction | - | Infix | Left | |
8 | List Construction | : | Infix | Right |
7 | Equal To | = | Infix | None |
Not Equal To | /= | Infix | None | |
Less Than | <: | Infix | None | |
Greater Than | :> | Infix | None | |
Less Than or Equal To | <= | Infix | None | |
Greater Than or Equal To | >= | Infix | None | |
6 | Logical OR | || | Infix | Left |
Logical AND | && | Infix | Left | |
5 | Assignment | := | Infix | None |
4 | Sequential | > P > | Infix | Right |
3 | Parallel | | | Infix | Left |
2 | Pruning | < P < | Infix | Left |
1 | Otherwise | ; | Infix | Left |
0 | Type Information | :: | Infix | Left |
Type Override | :!: | Infix | Left | |
Closure | lambda | Prefix | -- | |
Conditional | if then else | Prefix | -- | |
Declaration | val, def, import, include, type | Prefix | -- |