From Clomosy Docs

Operators are symbols and functions used in programming languages to perform various operations. They are used to carry out arithmetic, comparison, logical, and assignment operations between variables, constants, and other expressions.
TRObject allows the following types of operators:

  • Assignment Operators
  • Arithmetic Operators
  • Relational Operators
  • Boolean Operators

Assignment Operators

The assignment operator is a fundamental and important instruction in programming. It assigns the value of a calculated expression on the right side of the assignment symbol to a variable on the left side of the symbol.
Assignment is done using the equals sign (=).

var
  name : String;
{
  name = 'Clomosy';
}

Arithmetic Operators

Arithmetic operators are symbols used to perform mathematical operations. In programming, these operators allow us to carry out basic mathematical operations on numerical values.

Operator Description Example
+ Adds two operands 10 + 20 will give 30
- Subtracts second operand from the first 10 - 20 will give -10
* Multiplies both operands 10*20 will give 30
/ Divides numerator by denominator 20/10 will give 2
div Performs integer division and returns the integer part of the division result. The fractional part is ignored. 10 div 20 will give 0
mod Returns the remainder when one number is divided by another. 10 mod 20 will give 10
^ Performs exponentiation. 10 ^ 2 will give 100

Relational Operators

Relational operators are used to compare two values. The result of the comparison is either true (TRUE) or false (FALSE).

Operator Description Example
== Checks if the values of two operands are equal or not, if yes, then condition becomes true. (10 = 20) is not true.
<> Checks if the values of two operands are equal or not, if values are not equal, then condition becomes true. (10 <> 20) is true.
< Checks if the value of left operand is less than the value of right operand, if yes, then condition becomes true. (10 < 20) is true.
> Checks if the value of left operand is greater than the value of right operand, if yes, then condition becomes true. (10 > 20) is not true.
<= Checks if the value of left operand is less than or equal to the value of right operand, if yes, then condition becomes true. (10 <= 20) is true.
>= Checks if the value of left operand is greater than or equal to the value of right operand, if yes, then condition becomes true. (10 >= 20) is not true.

Boolean Operators

Boolean operators are used to perform logical operations and typically operate on two or more boolean (TRUE or FALSE) values.

Assume variable A holds true and variable B holds false, then:

Operator Description Example
&& If both the operands are true, then condition becomes true. (A and B) is false.
|| If any of the two operands is true, then condition becomes true. (A or B) is true.
not It reverses a boolean value. That is, it turns a TRUE value into FALSE, and a FALSE value into TRUE. not(10 = 20) is true.

Operators Precedence

Operator precedence determines the grouping of terms in an expression. This affects how an expression is evaluated. Certain operators have higher precedence than others; for example, the multiplication operator has higher precedence than the addition operator.

For example x = 7 + 3 * 2; here, x is assigned 13, not 20 because operator * has higher precedence than +, so it first gets multiplied with 3*2 and then adds into 7.

Here, operators with the highest precedence appear at the top of the table, those with the lowest appear at the bottom. Within an expression, higher precedence operators will be evaluated first.

Operators Precedence
*, /, div, mod, and Highest
+, -, or
=, <>, <, <=, >, >= Lowest