ASB expressions are combinations of variables, literal values, operators, functions and parentheses that can be reduced to a single value. Generally speaking, wherever you can use a single value or variable in a source rather than destination context, you can use an expression of arbitrary complexity. Although there are several types of variables, there are only two fundamental types of expressions: numeric—that evaluate to a floating point value—and string—that evaluate to a string. Mostly this is all quite familiar and intuitive, although there are few quirks—"mode independence", the overloaded + operator, and Boolean bit-wise arithmetic—which merit some discussion. First, though, let's review the complete list of operators:
Operator |
Precedence 1=highest |
Description |
^ |
1 |
Raise to power, e.g. 5^3 is 5 to the 3rd power or 125 |
** |
1 |
Equivalent to ^ |
+ |
2 |
Unary plus |
- |
2 |
Unary minus |
* |
3 |
Multiplication |
/ |
3 |
Division |
+ |
4 |
Addition or string concatenation |
- |
4 |
Subtraction |
= |
5 |
Relational equals, e.g. IF A = B OR C = D THEN ... |
< |
5 |
Relational less than; string or numeric |
<= |
5 |
Relational less than or equals; string or numeric |
> |
5 |
Relational greater than; string or numeric |
>= |
5 |
Relational greater than or equals; string or numeric |
<> |
5 |
Relational not equal; string or numeric |
# |
5 |
Relational not equal; same as <> |
NOT |
6 |
Logical NOT, e.g. IF NOT (A OR B) THEN ... |
AND |
7 |
Logical AND |
OR |
7 |
Logical OR |
XOR |
7 |
Logical XOR; exclusive OR |
EQV |
7 |
Logical equivalence; exclusive NOR |
MIN |
7 |
Minimum (of two operands), e.g. A = B MIN C + D |
MAX |
7 |
Maximum (of two operands), e.g. A = B + C MAX D + E |
USING |
8 |
Formatting, e.g. A USING "###.##" |
Mode Independence
This mysterious term, brought over from the original AlphaBASIC, refers to the ability to use and intermix string and numeric expressions, with the compiler and runtime interpreter performing conversions as necessary for the operations to make sense. For example, since multiplication only makes sense with numeric operands, if you supply string operands, they will be converted to numeric expressions automatically before the multiplication is performed. If a string starts with non-numeric characters, the corresponding value is simply zero. This is all fairly straightforward for operators and statements that expect a certain type of operand; the confusion comes with the + operator, which works with both strings and numbers.