Programming language Chora: Operators

Chora provides a rich set of build-in operators, you use to form arithmetic-logical expressions. The exact function of an operator depends on the data types of the operands involved in the operation. For example, the + (plus) operator will compute an arithmetic addition when used with two int32 operands, and a string concatenation when used with two string operands.

Depending on the number of operands, the operators are classified as unary or binary. Unary operators are always applied on a single operand. Binary operators, in turn, involve two operands into the expression. Following operators are available. Please remind, the exact function of an operator results from the data types of the involved operands. For details see the description of the respective operator:

Operator

Abstract description

=

Assignment

!

Logical NOT

~

Bitwise NOT

+

Plus operator

-

Minus operator

*

Multiplication

/

Division

%

Modulo division

>>

Right shift

<<

Left shift

&

AND

&&

Logical AND

|

OR

||

Logical OR

^

XOR

==

Equality

!=

Inequality

<

Less than

>

Greater than

<=

Less than or equal

>=

Greater than or equal

classof

Evaluate the class of an object

new

Create a new instance of a class

[]

Index operator

Operator precedence

Expressions in Chora are generally evaluated from left to right, whereby partial expressions enclosed in parentheses ( ... ) are evaluated first, so that the result of the partial expression can be used in the overall expression as operand. If the parentheses are missing, the order of evaluation within a complex expression is determined by the following precedence of operators:

Operators

Priority

unary + - ~

highest

* / %

+ -

<< >>

< <= > >=

== !=

&

^

|

&&

||

lowest

The above table means that in an expression, all unary operators are evaluated first followed by the *, / and % operators. Partial expressions that use a logical OR operator || are, on the other hand, evaluated last. This order can be changed explicitly by the programmer through the use of parentheses. As mentioned above, an expression in parentheses is always evaluated first. The following example demonstrates the effect:

var int32 result1 = 123 + 456 * 789;     // result1 = 359907
var int32 result2 = ( 123 + 456 ) * 789; // result2 = 456831