MC-Basic Operators

From SoftMC-Wiki
Revision as of 10:51, 10 December 2010 by Arwiebe (talk | contribs) (Imported from MC Reference.CHM)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
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 = 1
Inequality <> 1
Less than < 1
Greater than > 1
Less than or equal to <= 1
Greater than or equal to >= 1

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 1
And AND 2
Or OR 3
Exclusive Or XOR 4

Bit-wise Operators

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

Operation Symbol Relative Precedence
Bitwise complement BNOT 1
Bitwise And BAND 2
Bitwise Or BOR 3
Bitwise Exclusive Or BXOR 4

String concatenations

Performs concatenation of program or command line input. Usefull when input string is longer than translator buffer (128 chars).

Operation Symbol Relative Precedence
Concatenation \
Example
A = B + \
C + D

Is equal to:

A = B + C + D