Difference between revisions of "Operator precedence"

From D Wiki
Jump to: navigation, search
m (Remove extra cell, causing extra column)
(remove unordered comparison operators)
 
(3 intermediate revisions by 2 users not shown)
Line 1: Line 1:
  
 
{| class="wikitable"
 
{| class="wikitable"
! Priority || Description              || Operators   || Comments
+
! Priority || Description              || Operators               || Comments
 
|-
 
|-
| 15  
+
| 15       || Template instantiation  || <code>!</code>           || Top-level <code>,</code> in rhs expression treated specially. Cannot be chained.
highest
 
|| Template instantiation  || !          || Top-level ',' in rhs expression treated specially. Cannot be chained
 
 
|-
 
|-
| 14.5    || Lambda abstraction      || =>          || Not a real operator, occurs twice, this is binding power to the left.
+
| 14.5    || Lambda abstraction      || <code>=></code>          || Not a real operator, occurs twice, this is binding power to the left.
 
|-
 
|-
| 14      || Postfix operators        || . ++ -- ( [ || ( and [ treat top-level ',' in rhs expression specially and require balanced ) or ] in order to be completed
+
| 14      || Postfix operators        || <code>.</code> <code>++</code> <code>--</code> <code>(</code> <code>[</code> || <code>(</code> and <code>[</code> treat top-level <code>,</code> in rhs expression specially and require balanced <code>)</code> or <code>]</code> in order to be completed.
 
|-  
 
|-  
| 13      || Power operator          || ^^          || Right-associative
+
| 13      || Power operator          || <code>^^</code>         || Right-associative.
 
|-
 
|-
| 12      || Unary operators          || & ++ -- * + - ! ~ cast ||  
+
| 12      || Unary operators          || <code>&</code> <code>++</code> <code>--</code> <code>*</code> <code>+</code> <code>-</code> <code>!</code> <code>~</code> <code>cast</code> ||  
 
|-
 
|-
| 11      || -                        || * / %      ||  
+
| 11      || Multiplicative operators || <code>*</code> <code>/</code> <code>%</code>       ||  
 
|-
 
|-
| 10      || -                        || + - ~      || Binary '~' is the concatenation operator
+
| 10      || Additive operators      || <code>+</code> <code>-</code> <code>~</code>       || Binary <code>~</code> is the array concatenation operator.
 
|-
 
|-
| 9        || Bit shift operators      || << >> >>>  ||
+
| 9        || Bit shift operators      || <code><<</code> <code>>></code> <code>>>></code>  || <code>>>></code> is the always logical shift operator.
 
|-
 
|-
| 6a      || Comparison operators    || == != > < >= <= !> !< !>= !<= <> !<> <>= !<>= in !in is !is || Unordered with respect to bitwise operators, cannot be chained.
+
| 6a      || Comparison operators    || <code>==</code>  <code>!=</code>  <code>></code>  <code><</code> <code>>=</code> <code><=</code> <code>in</code> <code>!in</code> <code>is</code>  <code>!is</code>
 +
                                                                  || Unordered with respect to bitwise operators. Cannot be chained.
 
|-
 
|-
| 8b      || Bitwise AND             || &          || Unordered with respect to comparison operators
+
| 8b      || Bitwise And             || <code>&</code>           || Unordered with respect to comparison operators.
 
|-
 
|-
| 7b      || Bitwise XOR             || ^          || Unordered with respect to comparison operators
+
| 7b      || Bitwise Xor             || <code>^</code>           || Unordered with respect to comparison operators.
 
|-
 
|-
| 6b      || Bitwise OR               || <nowiki>|</nowiki>           || Unordered with respect to comparison operators
+
| 6b      || Bitwise Or               || <code><nowiki>|</nowiki></code>        || Unordered with respect to comparison operators.
 
|-
 
|-
| 5        || Logical AND             || &&          || Short-circuit
+
| 5        || Logical And             || <code>&&</code>         || Short-circuit.
 
|-
 
|-
| 4        || Logical OR               || <nowiki>||</nowiki>        || Short-circuit
+
| 4        || Logical Or               || <code><nowiki>||</nowiki></code>        || Short-circuit.
 
|-
 
|-
| 3        || Conditional operator    || ?:         || Right-associative
+
| 3        || Conditional operator    || <code>? :</code>        || Right-associative.
 
|-
 
|-
| 2        || Assignment operators    || /= &= |= -= += <<= >>= >>>= = *= %= ^= ^^= ~= || Right-associative
+
| 2        || Assignment operators    || <code>=</code> <code>^^=</code> <code>*=</code> <code>/=</code> <code>%=</code> <code>+=</code> <code>-=</code> <code>~=</code> <code><<=</code> <code>>>=</code> <code>>>>=</code> <code>&=</code> <code><nowiki>|=</nowiki></code> <code>^=</code>
 +
                                                                  || Right-associative.
 
|-
 
|-
| 1.5      || Lambda abstraction      || =>          || Not a real operator, occurs twice, this is binding power to the right
+
| 1.5      || Lambda abstraction      || <code>=></code>          || Not a real operator, occurs twice, this is binding power to the right.
 
|-
 
|-
| 1        || Comma operator          || ,          || Not to be confused with other uses of ',', though their precedence is the same
+
| 1        || Comma operator          || <code>,</code>           || Not to be confused with other uses of <code>,</code>, though their precedence is the same.
 
|-
 
|-
| 0         
+
| 0        || Range separator          || <code>..</code>         || Not a real operator, hardwired into syntax at specific points.
lowest
 
|| Range separator          || ..          || Not a real operator, hardwired into syntax at specific points
 
 
|}
 
|}
 +
 +
 +
[[Category:D Language]]

Latest revision as of 05:03, 3 November 2019

Priority Description Operators Comments
15 Template instantiation ! Top-level , in rhs expression treated specially. Cannot be chained.
14.5 Lambda abstraction => Not a real operator, occurs twice, this is binding power to the left.
14 Postfix operators . ++ -- ( [ ( and [ treat top-level , in rhs expression specially and require balanced ) or ] in order to be completed.
13 Power operator ^^ Right-associative.
12 Unary operators & ++ -- * + - ! ~ cast
11 Multiplicative operators * / %
10 Additive operators + - ~ Binary ~ is the array concatenation operator.
9 Bit shift operators << >> >>> >>> is the always logical shift operator.
6a Comparison operators == != > < >= <= in !in is !is Unordered with respect to bitwise operators. Cannot be chained.
8b Bitwise And & Unordered with respect to comparison operators.
7b Bitwise Xor ^ Unordered with respect to comparison operators.
6b Bitwise Or | Unordered with respect to comparison operators.
5 Logical And && Short-circuit.
4 Logical Or || Short-circuit.
3 Conditional operator ? : Right-associative.
2 Assignment operators = ^^= *= /= %= += -= ~= <<= >>= >>>= &= |= ^= Right-associative.
1.5 Lambda abstraction => Not a real operator, occurs twice, this is binding power to the right.
1 Comma operator , Not to be confused with other uses of ,, though their precedence is the same.
0 Range separator .. Not a real operator, hardwired into syntax at specific points.