Difference between revisions of "SHIP:Sail:Operators"

From Serious Documentation
Jump to: navigation, search
(Created page with "The following standard mathematical operators are available in Sail, listed in precedence order from first to last. Exceptions from C/Java are noted. {| class="wikitable" sty...")
 
Line 21: Line 21:
 
Function call
 
Function call
 
|-
 
|-
|rowspan=1|3
+
|3
 
|<nowiki>++ --</nowiki>
 
|<nowiki>++ --</nowiki>
 
<nowiki>+ -</nowiki>
 
<nowiki>+ -</nowiki>
Line 29: Line 29:
 
|Right-to-left
 
|Right-to-left
 
|-
 
|-
|rowspan=1|4
+
|4
|* / %||Multiplication, Division, Modulus
+
|<nowiki>* / %</nowiki>
 +
|Multiplication, Division, Modulus
 
|rowspan=10|Left-to-Right
 
|rowspan=10|Left-to-Right
 
|-
 
|-
|+ -||Addition, Subtraction
+
|5
 +
|<nowiki>+ -</nowiki>
 +
|Addition, Subtraction
 
|-
 
|-
|<< >>||Bitwise left, right shift
+
|6
 +
|<nowiki><< >></nowiki>
 +
|Bitwise left, right shift
 +
|-
 +
|7
 +
|<nowiki>< <=
 +
> >=</nowiki>
 +
|Less than, Less than or equal
 +
Greater than, greater than or equal
 +
|-
 +
|8
 +
|<nowiki>== !=</nowiki>
 +
|Equal, not equal
 +
|-
 +
|9
 +
|<nowiki>&</nowiki>
 +
|Bitwise AND
 +
|-
 +
|10
 +
|<nowiki>^</nowiki>
 +
|Bitwise XOR
 +
|-
 +
|11
 +
|<nowiki>|</nowiki>
 +
|Bitwise OR
 +
|-
 +
|12
 +
|<nowiki>&&</nowiki>
 +
|Logical AND
 +
|-
 +
|13
 +
|<nowiki>||</nowiki>
 +
|Logical OR
 +
|-
 +
|14
 +
|<nowiki>:?</nowiki>
 +
|Ternary Conditional
 +
|Right-to-Left; Expression between <nowiki>?</nowiki> and ? always parsed as if parenthesized.
 +
|-
 +
|15
 +
|<nowiki>=
 +
+= -=
 +
*= /= %=
 +
<<= >>=
 +
&= ^= |=</nowiki>
 +
|Assignment
 +
Add- and Subtract-assign
 +
Multiply-, Divide-, and Modulus-assign
 +
Bitwise left, right shift-assign
 +
Bitwise AND, XOR, OR assign
 +
|Right-to-Left
 
|}
 
|}
 
 
6 < <= For relational operators < and ≤ respectively
 
> >= For relational operators > and ≥ respectively
 
7 == != For relational = and ≠ respectively
 
8 & Bitwise AND
 
9 ^ Bitwise XOR (exclusive or)
 
10 | Bitwise OR (inclusive or)
 
11 && Logical AND
 
12 || Logical OR
 
13[note 1] ?: Ternary conditional[note 2] Right-to-Left
 
14 = Simple assignment
 
+= −= Assignment by sum and difference
 
*= /= %= Assignment by product, quotient, and remainder
 
<<= >>= Assignment by bitwise left shift and right shift
 
&= ^= |= Assignment by bitwise AND, XOR, and OR
 
15 , Comma Left-to-right
 

Revision as of 06:45, 13 May 2015

The following standard mathematical operators are available in Sail, listed in precedence order from first to last. Exceptions from C/Java are noted.

SHIPSail Operators and Precedence
Group Operator(s) Description Order
1 . Identifier qualification Left-to-right
2 ++ --

()

Post-increment/decrement

Function call

3 ++ --

+ - ! ~

Pre-increment/decrement

Logical/Bitwise NOT

Right-to-left
4 * / % Multiplication, Division, Modulus Left-to-Right
5 + - Addition, Subtraction
6 << >> Bitwise left, right shift
7 < <= > >= Less than, Less than or equal

Greater than, greater than or equal

8 == != Equal, not equal
9 & Bitwise AND
10 ^ Bitwise XOR
11 | Bitwise OR
12 && Logical AND
13 || Logical OR
14 :? Ternary Conditional Right-to-Left; Expression between ? and ? always parsed as if parenthesized.
15 = += -= *= /= %= <<= >>= &= ^= |= Assignment

Add- and Subtract-assign Multiply-, Divide-, and Modulus-assign Bitwise left, right shift-assign Bitwise AND, XOR, OR assign

Right-to-Left