Operators

An operator represents an operation to be carried out between two terms, such as a division.

tcSCRIPT supports five types of operators:

  • Arithmetic
  • Assignment
  • Comparative
  • Concatenation
  • Logical Operators

Arithmetic operators

Arithmetic operators can be applied to numeric constants and tcSCRIPT variables that evaluate to valid numbers. The following operators are listed in decreasing order of precedence:

- Unary prefix. Same as 0 – number (example -3).
+ Unary prefix. Same as 0 + number (example +3).
** Power
* Multiply
/ Divide
% Integer divide. Divide and return the integer part of the division
// Remainder divide. Divide and return the remainder of the division
+ Addition
- Subtraction

Assignment operators

Assignment operators are a means to change the value of a variable. tcSCRIPT only has one assignment operator.

= assign the value on the right side of the "=" to the variable on the left.

Comparative operators

The comparative operators compare two terms and return the logical value 1 if the result of the comparison is true, or 0 if the result of the comparison is false. The comparative operators will ignore leading or trailing blanks for string comparisons and leading zeros for numeric comparisons. Numeric comparisons are made if both terms to be compared are valid numbers, otherwise a string comparison is done. String comparisons are case-sensitive, and the shorter of the two strings is padded with blanks.

The following comparative operators are supported for operations on fields with different field lengths (non-strict operators).

= Equal
\=, ^= Not equal
> Greater than
< Less than
>= Greater than or equal
<= Less than or equal
<>, >< Greater than or less than; same as not equal

The following comparative operators are supported for operations on fields with identical field lengths (strict operators).

== Strictly equal
\==, ^== Strictly not equal
>> Strictly greater than
<< Strictly less than
>>= Strictly greater than or equal
<<= Strictly less than or equal

Concatenation operators

The concatenation operators combine two strings to form one by appending the second string to the right side of the first. The concatenation operators are:

  • (blank): Concatenation of strings with one space between them.
  • (abuttal): Concatenation of strings with no intervening space.
  • ||: Concatenation of strings with no intervening space.

Examples:

var1 = 'Hello';var2 = 'World'
Say var1 var2 -> results in 'Hello World'
Say a || b -> results in 'HelloWorld'
Say var1'World' -> results in 'HelloWorld'

Logical operators

Logical operators work with the strings 1 and 0, usually as a result of a comparative operator. These operators also only result in logical TRUE; 1 or logical FALSE; 0.

  • & AND returns 1 if both terms are 1.
    (4 > 2) & (a = a) /* true, so result is 1 */
    (2 > 4) & (a = a) /* false, so result is 0 */
  • | INCLUSIVE OR returns 1 if either term is 1.
    (4 > 2) | (5 = 3) /* at least one is true, so result is 1 */
    (2 > 4) | (5 = 3) /* neither one is true, so result is 0 */
  • && EXCLUSIVE OR returns 1 if either term is 1 but NOT both terms.
    (4 > 2) && (5 = 3) /* only one is true, so result is 1 */
    (4 > 2) && (5 = 5) /* both are true, so result is 0 */
    (2 > 4) && (5 = 3) /* neither one is true, so result is 0 */
  • \ LOGICAL NOT reverses the result; 0 becomes 1 and 1 becomes 0.
    \ 0  /* opposite of 0, so result is 1 */
    \ (4 > 2)  /* opposite of true, so result is 0 */