Simple operator precidence chart (and associativity)?

Timon Gehr timon.gehr at gmx.ch
Wed Mar 14 06:14:41 PDT 2012


On 03/14/2012 01:23 PM, Jos van Uden wrote:
> On 14-3-2012 0:14, Timon Gehr wrote:
>> I don't think there is, but I think I can create one:
>>
>> ! // 1 template instantiation
>> => // 2 goesto, binds weaker to the right
>> . ++ -- ( [ // 3 postfix operators
>> ^^ // 4 power (right-associative)
>> & ++ -- * - + ! ~ // 5 prefix operators
>> * / % // 6 multiplicative operators
>> + - ~ // 7 additive operators
>> >> << >>> // 8 shift operators
>> == != > < >= <= \ // 9 relational operators
>> !> !< !>= !<= <>\
>> !<> <>= !<>= in \
>> !in is !is
>> & // 10 bitwise AND (ambiguous with 9)
>> ^ // 11 bitwise XOR (ambiguous with 9)
>> | // 12 bitwise OR (ambiguous with 9)
>> && // 13 logical AND
>> || // 14 logical OR
>> ?: // 15 conditional operator
>> /= &= |= -= += \ // 16 assignment operators (right-associative)
>> <<= >>= >>>= = \
>> *= %= ^= ^^= ~=
>> => // 17 goesto, binds stronger to the left
>> , // 18 comma operator
>> .. // range (not actually an operator)
>
> The TDPL has a list of expressions in decreasing precedence
> on pages 61-63. Some of these operators, like <> or ^^= are
> not listed there.

Some guys want to deprecate <>, but I think it is actually quite nice. 
^^ and ^^= were added after TDPL was released afaik.

>
> Is there a difference between != and <> ?

Yes, != gives true when at least one of the arguments is NAN, while <> 
gives false if at least one of the arguments is NAN.

!= means not equal.
<> means ordered, but not equal.

There is also <>=, which just means ordered, etc.

>
> Why is the "goesto" operator listed twice? Is that accidental?
>

That is intentional. It binds stronger to the left than to the right, 
for example:

x+x=>x+x

will be parsed as:

x+(x=>(x+x))

(It could be argued that => is not a proper 'operator', but an operator 
precedence parser can be slightly more efficient if it is treated as one.)










More information about the Digitalmars-d-learn mailing list