Mathematical Operations
Till supports all mathematical operations like addition, subtraction, multiplication and division. Variables and statements that are involved in the operations are called the “operands”, and the mathematical operation codes (symbols) are called the “operators”. Operators that are composed of two identical characters are called “double operators”, and the operation result will be assigned to the left operand. The double operators also apply for non-mathematical operations.
MATHEMATICAL OPERATIONS
ACTIVITY | OPERATOR CODE (SYMBOL) | STRUCTURE | DESCRIPTION |
---|---|---|---|
increment (auto) | ++ (++) | a ++ | increment ‘a’ by one |
decrement (auto) | ‐‐ (--) | a –– | decrement ‘a’ by one |
multiply (auto) | ** (••) | a ** | multiply ‘a’ by itself |
add (static) | + (+) | a + 10.11 | add ‘a’ and 10.11 |
add (var) | + (+) | a + b | add ‘a’ and ‘b’ |
add (statement) | + (+) | a + statement | evaluate statement and add to ‘a’ |
subtract | – (-) | a – b | subtract ‘b’ from ‘a’ |
multiply | * (•) | a * b | multiply ‘a’ by ‘b’ |
divide | / (÷) | a / b | divide ‘a’ by ‘b’ |
add and assign | ++ (++) | a ++ b | ‘a’ is assigned by the sum of ‘a’ and ‘b’ |
composite operation | NA | a + b * c | add ‘a’ and the result of multiplication of ‘b’ by ‘c’ |
composite (parentheses) | NA | a + ( ( b + c * d) – e ) | first (recursively) evaluate the operation inside all parentheses, and then calculate the composite operation |
Non-Mathematical Operations
Till also supports addition of scalar components of various types, as well as other non-mathematical operations. Let’s assume that we have this code that will be used by table “Non-Mathematical Operations”:
str 'left-oper-'
var 100
list [ 1, 2 ]
tbool \t
fbool \f
a 'A'
b 'B'
func param: param
NON MATHEMATICAL OPERATIONS
CODE | RESULT | DESCRIPTION |
---|---|---|
str + 10 | left-oper-10 | append ’10’ |
str + var | left-oper-100 | append string representation of var |
str + list | left-oper-[ 1, 2 ] | append string representation of list |
str + func ‘param’ | left-oper-param | append result of calling function ‘func’ with argument ‘param’ |
str + tbool | left-oper-true | append string representation of the boolean variable |
tbool + fbool | TRUE | boolean OR operation |
tbool * fbool | FALSE | boolean AND operation |
tbool – fbool | TRUE | tbool is TRUE OR fbool is FALSE |
tbool / fbool | TRUE | tbool is TRUE AND fbool is FALSE |
str + fbool ? ‘YES’ \ ‘NO’ | YES | evaluate the condition statement “str + fbool” (result: TRUE), and return ‘YES’ |
str + ( fbool ? ‘YES’ \ ‘NO’ ) | left-oper-NO | append evaluation of the conditional statement that is enclosed in parentheses (result: ‘NO’) |
a + b ++ ‘C’ + ‘D’ | ABCD | according to Till Statement Order, the last addition statement yields ‘CD’, then it is appended and assigned to ‘b’ (‘b’ equals ‘BCD’), then it is appended to ‘a’ |
The last example shows that if a programmatic operation includes a double operator that is not the first operator, then the operation is not a composite mathematical expression. But if the only double operator is the first operator and the others are single operators then it will be an add and assign operation that the right operand is a composite mathematical expression.