Operators

This is a listing of the various operations on variables possible in Horse64, like addition, substraction, and so on. You may find this interesting as an expert user.

All operators will raise a TypeError if not applied to the supported types specified:

Math operators (T_MATH)

OperatorTypePurpose
A + BMathAdds two numbers.
A - BMathSubstracts one number from the other.
-AMathComputes the negated inverse of a number.
A * BMathMultiplies two numbers.
A / BMathMultiplies two numbers.
A % BMathComputes the modulo of a divsion.
A ^ BMathComputes the exponent of B over A.
A << BBitwiseBit shifts A left B times, zero padded.
A >> BBitwiseBit shifts A right B times, zero padded.
~ABitwiseInverts all the bits in A.
A & BBitwiseComputes bitwise "and" on the bits.
A &#124; BBitwiseComputes bitwise "or" on the bits.
A ^^ BBitwiseComputes bitwise "xor" on the bits.

(All operators except for - always take a left-hand and right-hand side, so they're all binary operators)

Comparison operators (T_COMPARE)

==, !=, >, <, >=, <=.

(These all take a left-hand and right-hand side, so they're all binary operators)

Boolean operators (T_BOOLCOMP)

not, and, or.

(The not operator only takes a right-hand side and is therefore unary, the others are binary operators.)

new operator (T_NEWOP)

new.

(It just takes a right-hand side, it's an unary operator.)

Example: new type_name(arg1, arg2)

Index by expression operator

[ with closing ].

(It takes both a right-hand and left-hand side, so it's a binary operator)

Example: somecontainer[<indexexpr>].

Attribute by identifier operator

. (dot).

(It has both right- and left-hand side, it's a binary operator)

Example: someitem.identifier.

Call operator

( with closing ).

(Also a binary operator with left- and right-hand side.)

Example: left_hand_called_side(right_hand_argument_side)

Operator precedences

If operators aren't clearly nested via parenthesis to indicate evaluation order, then it is determined by operator precedence. For simplicity, precedence is presented here by pasting the according implementation code of horsec found in src/compiler/operator.h64:

var precedence_table = [  # From closest-binding to loosest:
    ["new"],
    ['^'],
    [["-", token.T_UNARYMATH]],
    ["~", "&"],
    ["|"],
    ["^^"],
    ["/", "*", "%"],
    ["+", ["-", token.T_MATH]],
    ["<<", ">>"],
    [">=", "<=", ">", "<"],
    ["==", "!="],
    ["not"],
    ["and"],
    ["or"],
]
Privacy | Admin Contact | Misc