From dfe55a929d78657544e744f12c13d73983671b7f Mon Sep 17 00:00:00 2001 From: Denton Liu Date: Wed, 20 Jul 2016 15:29:28 -0400 Subject: Create order of precedence table --- docs/miscellaneous.rst | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) (limited to 'docs') diff --git a/docs/miscellaneous.rst b/docs/miscellaneous.rst index 825be2ce..55582eed 100644 --- a/docs/miscellaneous.rst +++ b/docs/miscellaneous.rst @@ -149,6 +149,64 @@ Tips and Tricks Cheatsheet ********** +.. index:: precedence + +Order of Precedence of Operators +================================ + +The following is the order of precedence for operators, listed in order of evaluation. + ++------------+-------------------------------------+--------------------------------------------+ +| Precedence | Description | Operator | ++============+=====================================+============================================+ +| *1* | Postfix increment and decrement | ``++``, ``--`` | ++ +-------------------------------------+--------------------------------------------+ +| | Function-like call | ``()`` | ++ +-------------------------------------+--------------------------------------------+ +| | Array subscripting | ``[]`` | ++ +-------------------------------------+--------------------------------------------+ +| | Member access | ``.`` | ++ +-------------------------------------+--------------------------------------------+ +| | Parentheses | ``()`` | ++------------+-------------------------------------+--------------------------------------------+ +| *2* | Prefix increment and decrement | ``++``, ``--`` | ++ +-------------------------------------+--------------------------------------------+ +| | Unary plus and minus | ``+``, ``-`` | ++ +-------------------------------------+--------------------------------------------+ +| | Logical NOT | ``!`` | ++ +-------------------------------------+--------------------------------------------+ +| | Bitwise NOT | ``~`` | ++------------+-------------------------------------+--------------------------------------------+ +| *3* | Exponentiation | ``**`` | ++------------+-------------------------------------+--------------------------------------------+ +| *4* | Multiplication, division and modulo | ``*``, ``/``, ``%`` | ++------------+-------------------------------------+--------------------------------------------+ +| *5* | Addition and subtraction | ``+``, ``-`` | ++------------+-------------------------------------+--------------------------------------------+ +| *6* | Bitwise shift operators | ``<<``, ``>>``, ``>>>`` | ++------------+-------------------------------------+--------------------------------------------+ +| *7* | Bitwise AND | ``&`` | ++------------+-------------------------------------+--------------------------------------------+ +| *8* | Bitwise XOR | ``^`` | ++------------+-------------------------------------+--------------------------------------------+ +| *9* | Bitwise OR | ``|`` | ++------------+-------------------------------------+--------------------------------------------+ +| *10* | Inequality operators | ``<``, ``>``, ``<=``, ``>=`` | ++------------+-------------------------------------+--------------------------------------------+ +| *11* | Equality operators | ``==``, ``!=`` | ++------------+-------------------------------------+--------------------------------------------+ +| *12* | Logical AND | ``&&`` | ++------------+-------------------------------------+--------------------------------------------+ +| *13* | Logical OR | ``||`` | ++------------+-------------------------------------+--------------------------------------------+ +| *14* | Ternary operator | `` ? : `` | ++------------+-------------------------------------+--------------------------------------------+ +| *15* | Assignment operators | ``=``, ``|=``, ``^=``, ``&=``, ``<<=``, | +| | | ``/=``, ``%=`` | ++------------+-------------------------------------+--------------------------------------------+ +| *16* | Comma operator | ``,`` | ++------------+-------------------------------------+--------------------------------------------+ + .. index:: block, coinbase, difficulty, number, block;number, timestamp, block;timestamp, msg, data, gas, sender, value, now, gas price, origin, sha3, ripemd160, sha256, ecrecover, addmod, mulmod, cryptography, this, super, selfdestruct, balance, send Global Variables -- cgit v1.2.3 From 5d09211d50c4284d936ef725b7d4dd693aef620a Mon Sep 17 00:00:00 2001 From: Denton Liu Date: Wed, 20 Jul 2016 15:35:38 -0400 Subject: Add link to operator table --- docs/miscellaneous.rst | 2 ++ docs/types.rst | 3 +++ 2 files changed, 5 insertions(+) (limited to 'docs') diff --git a/docs/miscellaneous.rst b/docs/miscellaneous.rst index 55582eed..83bbb828 100644 --- a/docs/miscellaneous.rst +++ b/docs/miscellaneous.rst @@ -151,6 +151,8 @@ Cheatsheet .. index:: precedence +.. _order: + Order of Precedence of Operators ================================ diff --git a/docs/types.rst b/docs/types.rst index 50e86ed0..d7681ee5 100644 --- a/docs/types.rst +++ b/docs/types.rst @@ -12,6 +12,9 @@ see :ref:`type-deduction` below) at compile-time. Solidity provides several elementary types which can be combined to form complex types. +In addition, types can interact with each other in expressions containing +operators. For a quick reference of the various operators, see :ref:`order`. + .. index:: ! value type, ! type;value Value Types -- cgit v1.2.3 From 1ec74f8cc4b952331b3003e2326eb90aa7fc2e55 Mon Sep 17 00:00:00 2001 From: Denton Liu Date: Tue, 26 Jul 2016 13:54:17 -0400 Subject: Remove comma operator --- docs/miscellaneous.rst | 3 --- 1 file changed, 3 deletions(-) (limited to 'docs') diff --git a/docs/miscellaneous.rst b/docs/miscellaneous.rst index 83bbb828..46867ab5 100644 --- a/docs/miscellaneous.rst +++ b/docs/miscellaneous.rst @@ -206,8 +206,6 @@ The following is the order of precedence for operators, listed in order of evalu | *15* | Assignment operators | ``=``, ``|=``, ``^=``, ``&=``, ``<<=``, | | | | ``/=``, ``%=`` | +------------+-------------------------------------+--------------------------------------------+ -| *16* | Comma operator | ``,`` | -+------------+-------------------------------------+--------------------------------------------+ .. index:: block, coinbase, difficulty, number, block;number, timestamp, block;timestamp, msg, data, gas, sender, value, now, gas price, origin, sha3, ripemd160, sha256, ecrecover, addmod, mulmod, cryptography, this, super, selfdestruct, balance, send @@ -265,4 +263,3 @@ Modifiers - ``constant`` for functions: Disallows modification of state - this is not enforced yet. - ``anonymous`` for events: Does not store event signature as topic. - ``indexed`` for event parameters: Stores the parameter as topic. - -- cgit v1.2.3 From ca5e6a6bd4734483c2ead97562286f9c32033bc0 Mon Sep 17 00:00:00 2001 From: Denton Liu Date: Tue, 26 Jul 2016 14:01:01 -0400 Subject: Fix assignment operators --- docs/miscellaneous.rst | 1 + 1 file changed, 1 insertion(+) (limited to 'docs') diff --git a/docs/miscellaneous.rst b/docs/miscellaneous.rst index 46867ab5..dd4bb9b0 100644 --- a/docs/miscellaneous.rst +++ b/docs/miscellaneous.rst @@ -204,6 +204,7 @@ The following is the order of precedence for operators, listed in order of evalu | *14* | Ternary operator | `` ? : `` | +------------+-------------------------------------+--------------------------------------------+ | *15* | Assignment operators | ``=``, ``|=``, ``^=``, ``&=``, ``<<=``, | +| | | ``>>=``, ``>>>=``, ``+=``, ``-=``, ``*=``, | | | | ``/=``, ``%=`` | +------------+-------------------------------------+--------------------------------------------+ -- cgit v1.2.3 From 71438157ce8455cbc14939b95e1a28236f10ed46 Mon Sep 17 00:00:00 2001 From: Denton Liu Date: Wed, 27 Jul 2016 10:26:39 -0400 Subject: Revert "Remove comma operator" This reverts commit 1ec74f8cc4b952331b3003e2326eb90aa7fc2e55. --- docs/miscellaneous.rst | 3 +++ 1 file changed, 3 insertions(+) (limited to 'docs') diff --git a/docs/miscellaneous.rst b/docs/miscellaneous.rst index dd4bb9b0..61dc9a16 100644 --- a/docs/miscellaneous.rst +++ b/docs/miscellaneous.rst @@ -207,6 +207,8 @@ The following is the order of precedence for operators, listed in order of evalu | | | ``>>=``, ``>>>=``, ``+=``, ``-=``, ``*=``, | | | | ``/=``, ``%=`` | +------------+-------------------------------------+--------------------------------------------+ +| *16* | Comma operator | ``,`` | ++------------+-------------------------------------+--------------------------------------------+ .. index:: block, coinbase, difficulty, number, block;number, timestamp, block;timestamp, msg, data, gas, sender, value, now, gas price, origin, sha3, ripemd160, sha256, ecrecover, addmod, mulmod, cryptography, this, super, selfdestruct, balance, send @@ -264,3 +266,4 @@ Modifiers - ``constant`` for functions: Disallows modification of state - this is not enforced yet. - ``anonymous`` for events: Does not store event signature as topic. - ``indexed`` for event parameters: Stores the parameter as topic. + -- cgit v1.2.3 From 8bf96b1c43febe3c082a9d60af6ebdc44d4eca68 Mon Sep 17 00:00:00 2001 From: Denton Liu Date: Wed, 27 Jul 2016 10:30:20 -0400 Subject: Remove >>> and >>>= operators --- docs/miscellaneous.rst | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'docs') diff --git a/docs/miscellaneous.rst b/docs/miscellaneous.rst index 61dc9a16..e56b1d24 100644 --- a/docs/miscellaneous.rst +++ b/docs/miscellaneous.rst @@ -185,7 +185,7 @@ The following is the order of precedence for operators, listed in order of evalu +------------+-------------------------------------+--------------------------------------------+ | *5* | Addition and subtraction | ``+``, ``-`` | +------------+-------------------------------------+--------------------------------------------+ -| *6* | Bitwise shift operators | ``<<``, ``>>``, ``>>>`` | +| *6* | Bitwise shift operators | ``<<``, ``>>`` | +------------+-------------------------------------+--------------------------------------------+ | *7* | Bitwise AND | ``&`` | +------------+-------------------------------------+--------------------------------------------+ @@ -204,8 +204,8 @@ The following is the order of precedence for operators, listed in order of evalu | *14* | Ternary operator | `` ? : `` | +------------+-------------------------------------+--------------------------------------------+ | *15* | Assignment operators | ``=``, ``|=``, ``^=``, ``&=``, ``<<=``, | -| | | ``>>=``, ``>>>=``, ``+=``, ``-=``, ``*=``, | -| | | ``/=``, ``%=`` | +| | | ``>>=``, ``+=``, ``-=``, ``*=``, ``/=``, | +| | | ``%=`` | +------------+-------------------------------------+--------------------------------------------+ | *16* | Comma operator | ``,`` | +------------+-------------------------------------+--------------------------------------------+ -- cgit v1.2.3 From 7a203241420fa266cff5640acdc9015f04804901 Mon Sep 17 00:00:00 2001 From: Denton Liu Date: Thu, 28 Jul 2016 15:16:52 -0400 Subject: Link to order of precedence table --- docs/control-structures.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'docs') diff --git a/docs/control-structures.rst b/docs/control-structures.rst index f30a5bdd..9d7ebeac 100644 --- a/docs/control-structures.rst +++ b/docs/control-structures.rst @@ -113,7 +113,7 @@ The evaluation order of expressions is not specified (more formally, the order in which the children of one node in the expression tree are evaluated is not specified, but they are of course evaluated before the node itself). It is only guaranteed that statements are executed in order and short-circuiting for -boolean expressions is done. +boolean expressions is done. See :ref:`order` for more information. .. index:: ! assignment -- cgit v1.2.3 From 5687beb424663871d3d59c6bd12d71fff79d5200 Mon Sep 17 00:00:00 2001 From: Denton Liu Date: Thu, 28 Jul 2016 15:25:58 -0400 Subject: Add unary operations to the table --- docs/miscellaneous.rst | 2 ++ 1 file changed, 2 insertions(+) (limited to 'docs') diff --git a/docs/miscellaneous.rst b/docs/miscellaneous.rst index e56b1d24..26901946 100644 --- a/docs/miscellaneous.rst +++ b/docs/miscellaneous.rst @@ -175,6 +175,8 @@ The following is the order of precedence for operators, listed in order of evalu + +-------------------------------------+--------------------------------------------+ | | Unary plus and minus | ``+``, ``-`` | + +-------------------------------------+--------------------------------------------+ +| | Unary operations | ``after``, ``delete`` | ++ +-------------------------------------+--------------------------------------------+ | | Logical NOT | ``!`` | + +-------------------------------------+--------------------------------------------+ | | Bitwise NOT | ``~`` | -- cgit v1.2.3