Skip to content

Commit fdc3c8e

Browse files
authored
Merge pull request #13048 from shadyy41/moving-operator-precedence
Move operator precedence from cheatsheet to operators
2 parents 1543cfc + ecb7c0b commit fdc3c8e

File tree

2 files changed

+66
-60
lines changed

2 files changed

+66
-60
lines changed

docs/cheatsheet.rst

Lines changed: 2 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -2,70 +2,12 @@
22
Cheatsheet
33
**********
44

5-
.. index:: precedence
6-
7-
.. _order:
5+
.. index:: operator; precedence
86

97
Order of Precedence of Operators
108
================================
119

12-
The following is the order of precedence for operators, listed in order of evaluation.
13-
14-
+------------+-------------------------------------+--------------------------------------------+
15-
| Precedence | Description | Operator |
16-
+============+=====================================+============================================+
17-
| *1* | Postfix increment and decrement | ``++``, ``--`` |
18-
+ +-------------------------------------+--------------------------------------------+
19-
| | New expression | ``new <typename>`` |
20-
+ +-------------------------------------+--------------------------------------------+
21-
| | Array subscripting | ``<array>[<index>]`` |
22-
+ +-------------------------------------+--------------------------------------------+
23-
| | Member access | ``<object>.<member>`` |
24-
+ +-------------------------------------+--------------------------------------------+
25-
| | Function-like call | ``<func>(<args...>)`` |
26-
+ +-------------------------------------+--------------------------------------------+
27-
| | Parentheses | ``(<statement>)`` |
28-
+------------+-------------------------------------+--------------------------------------------+
29-
| *2* | Prefix increment and decrement | ``++``, ``--`` |
30-
+ +-------------------------------------+--------------------------------------------+
31-
| | Unary minus | ``-`` |
32-
+ +-------------------------------------+--------------------------------------------+
33-
| | Unary operations | ``delete`` |
34-
+ +-------------------------------------+--------------------------------------------+
35-
| | Logical NOT | ``!`` |
36-
+ +-------------------------------------+--------------------------------------------+
37-
| | Bitwise NOT | ``~`` |
38-
+------------+-------------------------------------+--------------------------------------------+
39-
| *3* | Exponentiation | ``**`` |
40-
+------------+-------------------------------------+--------------------------------------------+
41-
| *4* | Multiplication, division and modulo | ``*``, ``/``, ``%`` |
42-
+------------+-------------------------------------+--------------------------------------------+
43-
| *5* | Addition and subtraction | ``+``, ``-`` |
44-
+------------+-------------------------------------+--------------------------------------------+
45-
| *6* | Bitwise shift operators | ``<<``, ``>>`` |
46-
+------------+-------------------------------------+--------------------------------------------+
47-
| *7* | Bitwise AND | ``&`` |
48-
+------------+-------------------------------------+--------------------------------------------+
49-
| *8* | Bitwise XOR | ``^`` |
50-
+------------+-------------------------------------+--------------------------------------------+
51-
| *9* | Bitwise OR | ``|`` |
52-
+------------+-------------------------------------+--------------------------------------------+
53-
| *10* | Inequality operators | ``<``, ``>``, ``<=``, ``>=`` |
54-
+------------+-------------------------------------+--------------------------------------------+
55-
| *11* | Equality operators | ``==``, ``!=`` |
56-
+------------+-------------------------------------+--------------------------------------------+
57-
| *12* | Logical AND | ``&&`` |
58-
+------------+-------------------------------------+--------------------------------------------+
59-
| *13* | Logical OR | ``||`` |
60-
+------------+-------------------------------------+--------------------------------------------+
61-
| *14* | Ternary operator | ``<conditional> ? <if-true> : <if-false>`` |
62-
+ +-------------------------------------+--------------------------------------------+
63-
| | Assignment operators | ``=``, ``|=``, ``^=``, ``&=``, ``<<=``, |
64-
| | | ``>>=``, ``+=``, ``-=``, ``*=``, ``/=``, |
65-
| | | ``%=`` |
66-
+------------+-------------------------------------+--------------------------------------------+
67-
| *15* | Comma operator | ``,`` |
68-
+------------+-------------------------------------+--------------------------------------------+
10+
:ref:`order`
6911

7012
.. index:: assert, block, coinbase, difficulty, number, block;number, timestamp, block;timestamp, msg, data, gas, sender, value, gas price, origin, revert, require, keccak256, ripemd160, sha256, ecrecover, addmod, mulmod, cryptography, this, super, selfdestruct, balance, codehash, send
7113

docs/types/operators.rst

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,3 +108,67 @@ value it referred to previously.
108108
assert(y.length == 0);
109109
}
110110
}
111+
112+
.. index:: ! operator; precedence
113+
.. _order:
114+
115+
Order of Precedence of Operators
116+
--------------------------------
117+
118+
The following is the order of precedence for operators, listed in order of evaluation.
119+
120+
+------------+-------------------------------------+--------------------------------------------+
121+
| Precedence | Description | Operator |
122+
+============+=====================================+============================================+
123+
| *1* | Postfix increment and decrement | ``++``, ``--`` |
124+
+ +-------------------------------------+--------------------------------------------+
125+
| | New expression | ``new <typename>`` |
126+
+ +-------------------------------------+--------------------------------------------+
127+
| | Array subscripting | ``<array>[<index>]`` |
128+
+ +-------------------------------------+--------------------------------------------+
129+
| | Member access | ``<object>.<member>`` |
130+
+ +-------------------------------------+--------------------------------------------+
131+
| | Function-like call | ``<func>(<args...>)`` |
132+
+ +-------------------------------------+--------------------------------------------+
133+
| | Parentheses | ``(<statement>)`` |
134+
+------------+-------------------------------------+--------------------------------------------+
135+
| *2* | Prefix increment and decrement | ``++``, ``--`` |
136+
+ +-------------------------------------+--------------------------------------------+
137+
| | Unary minus | ``-`` |
138+
+ +-------------------------------------+--------------------------------------------+
139+
| | Unary operations | ``delete`` |
140+
+ +-------------------------------------+--------------------------------------------+
141+
| | Logical NOT | ``!`` |
142+
+ +-------------------------------------+--------------------------------------------+
143+
| | Bitwise NOT | ``~`` |
144+
+------------+-------------------------------------+--------------------------------------------+
145+
| *3* | Exponentiation | ``**`` |
146+
+------------+-------------------------------------+--------------------------------------------+
147+
| *4* | Multiplication, division and modulo | ``*``, ``/``, ``%`` |
148+
+------------+-------------------------------------+--------------------------------------------+
149+
| *5* | Addition and subtraction | ``+``, ``-`` |
150+
+------------+-------------------------------------+--------------------------------------------+
151+
| *6* | Bitwise shift operators | ``<<``, ``>>`` |
152+
+------------+-------------------------------------+--------------------------------------------+
153+
| *7* | Bitwise AND | ``&`` |
154+
+------------+-------------------------------------+--------------------------------------------+
155+
| *8* | Bitwise XOR | ``^`` |
156+
+------------+-------------------------------------+--------------------------------------------+
157+
| *9* | Bitwise OR | ``|`` |
158+
+------------+-------------------------------------+--------------------------------------------+
159+
| *10* | Inequality operators | ``<``, ``>``, ``<=``, ``>=`` |
160+
+------------+-------------------------------------+--------------------------------------------+
161+
| *11* | Equality operators | ``==``, ``!=`` |
162+
+------------+-------------------------------------+--------------------------------------------+
163+
| *12* | Logical AND | ``&&`` |
164+
+------------+-------------------------------------+--------------------------------------------+
165+
| *13* | Logical OR | ``||`` |
166+
+------------+-------------------------------------+--------------------------------------------+
167+
| *14* | Ternary operator | ``<conditional> ? <if-true> : <if-false>`` |
168+
+ +-------------------------------------+--------------------------------------------+
169+
| | Assignment operators | ``=``, ``|=``, ``^=``, ``&=``, ``<<=``, |
170+
| | | ``>>=``, ``+=``, ``-=``, ``*=``, ``/=``, |
171+
| | | ``%=`` |
172+
+------------+-------------------------------------+--------------------------------------------+
173+
| *15* | Comma operator | ``,`` |
174+
+------------+-------------------------------------+--------------------------------------------+

0 commit comments

Comments
 (0)