MC-Basic Operators

From SoftMC-Wiki
Jump to: navigation, search

The tables shown below list the different types of operators, and their relative precedence. Arithmetic operators have the highest precedence, followed by Relational, Logical and Bit-wise operators. The relative precedence of the operators within each group is noted in the tables. Parentheses may be used to force a different order of expression processing because parentheses have the highest precedence. The “+” operator can be used to concatenate strings, and the “=” operator can be used to copy strings. The other operators have no applicability with strings.

The “=” operator can also be utilized to copy the entire values of an array to another array (matching in size and number of dimensions) through a single assignment statement. Other operators have no applicability with whole arrays.

Arithmetic Operators

Operation Symbol Relative Precedence
Exponentiation ^ 1
Negation/N/A minus - 2
Multiplication * 3
Division / 3
Modulus MOD 4
Addition + 5
Subtraction - 5

Relational Operators

Relational operators provide a method whereby two values may be compared. The result of the comparison is either TRUE (1) or FALSE (0). The operators are listed below; all Relational Operators have the same level of precedence, and relational operators have lower precedence than arithmetic operators. Relational operators may be used with any type of variable or value, including strings. String comparisons are made character-by-character, starting with the first character in each string, thus the string “de” is greater than the string “abc”. Character comparisons are made according to the value of the ASCII character codes for the respective characters.

Operation Symbol Relative Precedence
Equality = 6
Inequality <> 6
Less than < 6
Greater than > 6
Less than or equal to <= 6
Greater than or equal to >= 6

Logical Operators

Logical operators perform tests on multiple relations, and return a True (nonzero) or False (zero) value to be used in making a decision. Logical operators have lower precedence than Relational operators. They may be used on integer operands only (including the results of relational expressions).

Operation Symbol Relative Precedence
Complement NOT 7
And AND 8
Or OR 9
Exclusive Or XOR 10

Bitwise Operators

Bitwise operators perform bit manipulations on integer operands only. The result of the operation is a Long.

Operation Symbol Relative Precedence
Shift left SHL 4
Shift right SHR 4
Bitwise complement BNOT 11
Bitwise AND BAND 12
Bitwise OR BOR 13
Bitwise Exclusive OR BXOR 14