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:

ClassDescription
ArithmeticGeneral mathematical operations
BitwiseOperations on binary numbers
LogicalResult is always a boolean
AssignmentAssign values to variables
PointerManipulate pointers
OtherOther 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.

ClassUBFOSymbolDescriptionExample
Arithmetic1111+Arithmetic addition | Unary identitya + b or +a
Arithmetic1111-Arithmetic subtraction | Negate itema - b or -a
Arithmetic/Pointer1111*Arithmetic multiplication | Dereference a pointera * b or *a
Arithmetic0111/Arithmetic divisiona / b
Arithmetic0111%Arithmetic modulusa % b
Bitwise/Pointer1111&Bitwise AND | Take address ofa & b or &a
Bitwise0101|Bitwise ORa | b
Bitwise0101^Bitwise XORa ^ b
Bitwise1001~Bitwise NOT~a
Bitwise0101<<Bitwise left shifta << b
Bitwise/Arithmetic0101>>Right shifta >> b
Bitwise0101<<<Bitwise left rotatea <<< b
Bitwise0101>>>Bitwise right rotatea >>> b
Logical0111&&Logical ANDa && b
Logical0111||Logical ORa || b
Logical0111^^Logical XORa ^^ b
Logical1011!Logical NOT!a
Logical0111<Less thana < b
Logical0111>Greater thana > b
Logical0111<=Less than or equal toa <= b
Logical0111>=Greater than or equal toa >= b
Logical0111==Strict equalitya == b
Logical0111!=Strict inequalitya != b
Assignment0111=Assign RHS to LHSa = b
Assignment0111+=Arithmetic addition assignmenta += b
Assignment0111-=Arithmetic subtraction assignmenta -= b
Assignment0111*=Arithmetic multiplication assignmenta *= b
Assignment0111/=Arithmetic division assignmenta /= b
Assignment0111%=Arithmetic modulus assignmenta %= b
Assignment0101&=Bitwise AND assignmenta &= b
Assignment0101|=Bitwise OR assignmenta |= b
Assignment0101^=Bitwise XOR assignmenta ^= b
Assignment0111&&=Logical AND assignmenta &&= b
Assignment0111||=Logical OR assignmenta ||= b
Assignment0111^^=Logical XOR assignmenta ^^= b
Assignment0101<<=Bitwise left shift assignmenta <<= b
Assignment0101>>=Right shift assignmenta >>= b
Assignment0101<<<=Bitwise left rotate assignmenta <<<= b
Assignment0101>>>=Bitwise right rotate assignmenta >>>= b
Assignment1011++Incrementa++ or ++a
Assignment1011--Decrementa-- or --a
Other0111asGeneral type castinga as b
Other0110bitcast_asBitcast operatora bitcast_as b
Other0000inNot used directly in expressionsa in b
Other0000outNot used directly in expressionsa out b
Other1010sizeofSize of a type in bytessizeof(a)
Other1010bitsizeofSize of a type in bitsbitsizeof(a)
Other1010alignofAlignment of a type in bytesalignof(a)
Other1010typeofType of an expressiontypeof(a)
Other0110.Access member of a structa.b
Other0111..Range operatora..b
Other0000...Ellipsis operatora...b
Other0000=>Lambda operatora => b
Other0010?Ternary operatora ? b : c

Formal Definition

<operator> ::=  "+" | "-" | "*" | "/" | "%" | "&" | "|" | "^"   |
                "~" | "<<" | ">>" | "<<<" | ">>>" | "&&" | "||" |
                "^^" | "!" | "<" | ">" | "<=" | ">=" | "=="     |
                "!=" | "=" | "+=" | "-=" | "*=" | "/=" | "%="   |
                "&=" | "|=" | "^=" | "&&=" | "||=" | "^^="      |
                "<<=" | ">>=" | "<<<=" | ">>>=" | "++" | "--"   |
                "as" | "bitcast_as" | "in" | "out" | "sizeof"   |
                "bitsizeof" | "alignof" | "typeof" | "." | ".." |
                "..." | "=>" | "?"