Operators - The Nitrate Programming Language
Nitrate language operators are generally the vechiles for computation and manipulation of data. The following tables contain a list of symbols that have special meaning in the language.
Classification of Operators
Operators are classified into the following categories:
Class | Description |
---|---|
Arithmetic | General mathematical operations |
Bitwise | Operations on binary numbers |
Logical | Result is always a boolean |
Assignment | Assign values to variables |
Pointer | Manipulate pointers |
Other | Other operators |
Complete Table of Operators
Note: U
and B
in the table below indicate whether the operator supports unary expressions and binary expressions, respectively.
Note: F
in the table below indicates whether the builtin operator supports floating-point numbers or not.
Note: O
in the table below indicates if the operator can be overloaded.
Class | U | B | F | O | Symbol | Description | Example |
---|---|---|---|---|---|---|---|
Arithmetic | 1 | 1 | 1 | 1 | + | Arithmetic addition | Unary identity | a + b or +a |
Arithmetic | 1 | 1 | 1 | 1 | - | Arithmetic subtraction | Negate item | a - b or -a |
Arithmetic/Pointer | 1 | 1 | 1 | 1 | * | Arithmetic multiplication | Dereference a pointer | a * b or *a |
Arithmetic | 0 | 1 | 1 | 1 | / | Arithmetic division | a / b |
Arithmetic | 0 | 1 | 1 | 1 | % | Arithmetic modulus | a % b |
Bitwise/Pointer | 1 | 1 | 1 | 1 | & | Bitwise AND | Take address of | a & b or &a |
Bitwise | 0 | 1 | 0 | 1 | | | Bitwise OR | a | b |
Bitwise | 0 | 1 | 0 | 1 | ^ | Bitwise XOR | a ^ b |
Bitwise | 1 | 0 | 0 | 1 | ~ | Bitwise NOT | ~a |
Bitwise | 0 | 1 | 0 | 1 | << | Bitwise left shift | a << b |
Bitwise/Arithmetic | 0 | 1 | 0 | 1 | >> | Right shift | a >> b |
Bitwise | 0 | 1 | 0 | 1 | <<< | Bitwise left rotate | a <<< b |
Bitwise | 0 | 1 | 0 | 1 | >>> | Bitwise right rotate | a >>> b |
Logical | 0 | 1 | 1 | 1 | && | Logical AND | a && b |
Logical | 0 | 1 | 1 | 1 | || | Logical OR | a || b |
Logical | 0 | 1 | 1 | 1 | ^^ | Logical XOR | a ^^ b |
Logical | 1 | 0 | 1 | 1 | ! | Logical NOT | !a |
Logical | 0 | 1 | 1 | 1 | < | Less than | a < b |
Logical | 0 | 1 | 1 | 1 | > | Greater than | a > b |
Logical | 0 | 1 | 1 | 1 | <= | Less than or equal to | a <= b |
Logical | 0 | 1 | 1 | 1 | >= | Greater than or equal to | a >= b |
Logical | 0 | 1 | 1 | 1 | == | Strict equality | a == b |
Logical | 0 | 1 | 1 | 1 | != | Strict inequality | a != b |
Assignment | 0 | 1 | 1 | 1 | = | Assign RHS to LHS | a = b |
Assignment | 0 | 1 | 1 | 1 | += | Arithmetic addition assignment | a += b |
Assignment | 0 | 1 | 1 | 1 | -= | Arithmetic subtraction assignment | a -= b |
Assignment | 0 | 1 | 1 | 1 | *= | Arithmetic multiplication assignment | a *= b |
Assignment | 0 | 1 | 1 | 1 | /= | Arithmetic division assignment | a /= b |
Assignment | 0 | 1 | 1 | 1 | %= | Arithmetic modulus assignment | a %= b |
Assignment | 0 | 1 | 0 | 1 | &= | Bitwise AND assignment | a &= b |
Assignment | 0 | 1 | 0 | 1 | |= | Bitwise OR assignment | a |= b |
Assignment | 0 | 1 | 0 | 1 | ^= | Bitwise XOR assignment | a ^= b |
Assignment | 0 | 1 | 1 | 1 | &&= | Logical AND assignment | a &&= b |
Assignment | 0 | 1 | 1 | 1 | ||= | Logical OR assignment | a ||= b |
Assignment | 0 | 1 | 1 | 1 | ^^= | Logical XOR assignment | a ^^= b |
Assignment | 0 | 1 | 0 | 1 | <<= | Bitwise left shift assignment | a <<= b |
Assignment | 0 | 1 | 0 | 1 | >>= | Right shift assignment | a >>= b |
Assignment | 0 | 1 | 0 | 1 | <<<= | Bitwise left rotate assignment | a <<<= b |
Assignment | 0 | 1 | 0 | 1 | >>>= | Bitwise right rotate assignment | a >>>= b |
Assignment | 1 | 0 | 1 | 1 | ++ | Increment | a++ or ++a |
Assignment | 1 | 0 | 1 | 1 | -- | Decrement | a-- or --a |
Other | 0 | 1 | 1 | 1 | as | General type casting | a as b |
Other | 0 | 1 | 1 | 0 | bitcast_as | Bitcast operator | a bitcast_as b |
Other | 0 | 0 | 0 | 0 | in | Not used directly in expressions | a in b |
Other | 0 | 0 | 0 | 0 | out | Not used directly in expressions | a out b |
Other | 1 | 0 | 1 | 0 | sizeof | Size of a type in bytes | sizeof(a) |
Other | 1 | 0 | 1 | 0 | bitsizeof | Size of a type in bits | bitsizeof(a) |
Other | 1 | 0 | 1 | 0 | alignof | Alignment of a type in bytes | alignof(a) |
Other | 1 | 0 | 1 | 0 | typeof | Type of an expression | typeof(a) |
Other | 0 | 1 | 1 | 0 | . | Access member of a struct | a.b |
Other | 0 | 1 | 1 | 1 | .. | Range operator | a..b |
Other | 0 | 0 | 0 | 0 | ... | Ellipsis operator | a...b |
Other | 0 | 0 | 0 | 0 | => | Lambda operator | a => b |
Other | 0 | 0 | 1 | 0 | ? | Ternary operator | a ? b : c |
Formal Definition
<operator> ::= "+" | "-" | "*" | "/" | "%" | "&" | "|" | "^" |
"~" | "<<" | ">>" | "<<<" | ">>>" | "&&" | "||" |
"^^" | "!" | "<" | ">" | "<=" | ">=" | "==" |
"!=" | "=" | "+=" | "-=" | "*=" | "/=" | "%=" |
"&=" | "|=" | "^=" | "&&=" | "||=" | "^^=" |
"<<=" | ">>=" | "<<<=" | ">>>=" | "++" | "--" |
"as" | "bitcast_as" | "in" | "out" | "sizeof" |
"bitsizeof" | "alignof" | "typeof" | "." | ".." |
"..." | "=>" | "?"