Operator precedence: Difference between revisions

Add Ecstasy table
(→‎dc: add)
(Add Ecstasy table)
 
(4 intermediate revisions by 2 users not shown)
Line 858:
=={{header|Delphi}}==
See table at [[#Free Pascal|Free Pascal]].
 
=={{header|Ecstasy}}==
 
Ecstasy's precedence table is based loosely on the C family of languages, but with significant tweaks to support the most common patterns without parenthesis. At a given level of precedence, all evaluation is from left to right.
 
{| class="wikitable"
! Order !! Operator !! Description !! Associativity
|-
| 1 || & || Unary reference-of, based on C syntax || Right-to-left
|-
| 2 || ++ || Post-increment || Left-to-right
|-
| || -- || Post-decrement ||
|-
| || () || Invoke method / call function ||
|-
| || [] || Array access ||
|-
| || ? || Postfix conditional ||
|-
| || . || Access object member ||
|-
| || .new || Postfix object creation ||
|-
| || .as || Postfix type assertion ||
|-
| || .is || Postfix type comparison ||
|-
| 3 || ++ || Pre-increment || Right-to-left
|-
| || -- || Pre-decrement ||
|-
| || + || Unary plus ||
|-
| || - || Unary minus ||
|-
| || ! || Logical NOT ||
|-
| || ~ || Bitwise NOT ||
|-
| 4 || ?: || Conditional "Elvis" || Right-to-left
|-
| 5 || * || Multiply || Left-to-right
|-
| || / || Divide ||
|-
| || % || Modulo ||
|-
| || / || Divide with remainder ||
|-
| 6 || + || Add || Left-to-right
|-
| || - || Subtract ||
|-
| 7 || << || Shift left || Left-to-right
|-
| || >> || Arithmetic shift right ||
|-
| || >>> || Logical shift right ||
|-
| || & || And ||
|-
| || ^ || Xor ||
|-
| || <nowiki>|</nowiki> || Or ||
|-
| 8 || .. || Range/intervale || Left-to-right
|-
| 9 || <- || Assignment || Right-to-left
|-
| 10 || < <= > >= || Relational || Left-to-right
|-
| || <=> || Order ||
|-
| 11 || == || Equality || Left-to-right
|-
| || != || Inequality ||
|-
| 12 || && || Conditional AND || Left-to-right
|-
| 13 || ^^ || Conditional XOR || Left-to-right
|-
| || <nowiki>||</nowiki> || Conditional OR ||
|-
| 14 || ? : || Conditional ternary || Right-to-left
|-
| 15 || : || Conditional ELSE || Right-to-left
|}
 
=={{header|Eiffel}}==
Line 1,633 ⟶ 1,721:
Such an expression "1+2*3+4" is written {+ 1 {* 2 3} 4}
</syntaxhighlight>
 
=={{header|Lang}}==
<pre>
# Precedence | Operator | Associativity | Operator name
# ===========|====================|===============|==========================================
# 0 | (opr) | - | Grouping
# | opr1(opr2) | left-to-right | Function calls
# | opr1[opr2] | left-to-right | Get item
# | opr1?.[opr2] | left-to-right | Optional get item
# | opr1::opr2 | left-to-right | Member access [1]
# | opr1?::opr2 | left-to-right | Optional member access [1]
# | opr1->opr2 | left-to-right | Member access pointer [1]
# -----------|--------------------|---------------|------------------------------------------
# 1 | @opr | right-to-left | Length
# | ^opr | | Deep copy
# -----------|--------------------|---------------|------------------------------------------
# 2 | opr1 ** opr2 | right-to-left | Power [2]
# -----------|--------------------|---------------|------------------------------------------
# 3 | +opr | right-to-left | Positive
# | -opr | | Inverse
# | ~opr | | Bitwise not
# | +|opr | | Increment
# | ▲opr | | Increment [Alternative non-ascii symbol]
# | -|opr | | Decrement
# | ▼opr | | Decrement [Alternative non-ascii symbol]
# | !opr | | Not
# -----------|--------------------|---------------|------------------------------------------
# 4 | opr1 * opr2 | left-to-right | Multiplication
# | opr1 / opr2 | | Division
# | opr1 ~/ opr2 | | Truncation division
# | opr1 // opr2 | | Floor division
# | opr1 ^/ opr2 | | Ceil division
# | opr1 % opr2 | | Modulo
# -----------|--------------------|---------------|------------------------------------------
# 5 | opr1 ||| opr2 | left-to-right | Concat
# | opr1 + opr2 | | Addition
# | opr1 - opr2 | | Subtraction
# -----------|--------------------|---------------|------------------------------------------
# 6 | opr1 << opr2 | left-to-right | Left shift
# | opr1 >> opr2 | | Right shift
# | opr1 >>> opr2 | | Right zero shift
# -----------|--------------------|---------------|------------------------------------------
# 7 | opr1 & opr2 | left-to-right | Bitwise and
# -----------|--------------------|---------------|------------------------------------------
# 8 | opr1 ^ opr2 | left-to-right | Bitwsie xor
# -----------|--------------------|---------------|------------------------------------------
# 9 | opr1 | opr2 | left-to-right | Bitwise or
# -----------|--------------------|---------------|------------------------------------------
# 10 | opr1 <=> opr2 | left-to-right | Spaceship
# | opr1 ~~ opr2 | | Instance of
# | opr1 == opr2 | | Equals
# | opr1 != opr2 | | Not equals
# | opr1 =~ opr2 | | Matches
# | opr1 !=~ opr2 | | Not matches
# | opr1 === opr2 | | Strict equals
# | opr1 !== opr2 | | Strict not equals
# | opr1 < opr2 | | Less than
# | opr1 > opr2 | | Greater than
# | opr1 <= opr2 | | Less than or equals
# | opr1 >= opr2 | | Greater than or equals
# -----------|--------------------|---------------|------------------------------------------
# 11 | opr1 && opr2 | left-to-right | And
# -----------|--------------------|---------------|------------------------------------------
# 12 | opr1 || opr2 | left-to-right | Or
# -----------|--------------------|---------------|------------------------------------------
# 13 | opr1 ?: opr2 | left-to-right | Elvis
# | opr1 ?? opr2 | | Null coalescing
# -----------|--------------------|---------------|------------------------------------------
# 14 | opr1 ? opr2 : opr3 | right-to-left | Inline if
# -----------|--------------------|---------------|------------------------------------------
# 15 | opr1 , opr2 | left-to-right | Comma
# -----------|--------------------|---------------|------------------------------------------
# 16 | opr1 = opr2 | right-to-left | Normal assignment
# | opr1 = opr2 | | Translation
# | opr1 ::= opr2 | | Lvalue operation assignment
# | opr1 ?= opr2 | | Condition operator assignment
# | opr1 := opr2 | | Math operator assignment
# | opr1 $= opr2 | | Operation operator assignment
# | opr1 += opr2 | | Addition assignment
# | opr1 -= opr2 | | Subtraction assignment
# | opr1 *= opr2 | | Multiplication assignment
# | opr1 /= opr2 | | Division assignment
# | opr1 ~/= opr2 | | Truncation division assignment
# | opr1 //= opr2 | | Floor division assignment
# | opr1 ^/= opr2 | | Ceil division assignment
# | opr1 **= opr2 | | Power assignment
# | opr1 %= opr2 | | Modulo assignment
# | opr1 >>= opr2 | | Right shift assignment
# | opr1 >>>= opr2 | | Right zero shift assignment
# | opr1 <<= opr2 | | Left shift assignment
# | opr1 &= opr2 | | Bitwise and assignment
# | opr1 ^= opr2 | | Bitwise xor assignment
# | opr1 |= opr2 | | Bitwise or assignment
# | opr1 |||= opr2 | | Concat assignment
# | opr1 ?:= opr2 | | Elvis assignment
# | opr1 ??= opr2 | | Null coalescing assignment
#
# Footnotes:
# 1) The unary operators (@, ^, +, -, ~, +|, ▲, -|, ▼, and !) have a higher binding than the member access operators if they are on the right of the member access operator.
# 2) The unary operators (+, -, ~, +|, ▲, -|, ▼, and !) have a higher binding than the power operator if they are on the right of the power operator.
#
# Some operators have multiple meanings but they keep the same precedence and associativity
</pre>
 
=={{header|LIL}}==
Line 1,886 ⟶ 2,077:
[https://ocaml.org/manual/expr.html#ss:precedence-and-associativity This table] contains the precedence and associativity of operators and other expression constructs in OCaml, including user-defined operators.
 
=={{header|Odin}}==
Unary operators have the highest precedence.
 
There are seven precedence levels for binary and ternary operators.
 
{| class="wikitable"
!Precedence !! Operator
|-
|| 7 || <code>*</code> <code>/</code> <code>%</code> <code>%%</code> <code>&</code> <code>&~</code> <code><<</code> <code>>></code>
|-
|| 6 || <code>+</code> <code>-</code> <code><nowiki>|</nowiki></code> <code>~</code> <code>in</code> <code>not_in</code>
|-
|| 5 || <code>==</code> <code>!=</code> <code><</code> <code>></code> <code><=</code> </code>>=</code>
|-
|| 4 || <code>&&</code>
|-
|| 3 || <code><nowiki>||</nowiki></code>
|-
|| 2 || <code>..=</code> <code>..<</code>
|-
|| 1 || <code>or_else</code> <code>?</code> <code>if</code> <code>when</code>
|}
Binary operators of the same precedence associate from left to right. For instance "x / y * z" is the same as "(x / y) * z"
=={{header|Oforth}}==
 
162

edits