Expressions:  


Expressions

Operators

BlitzMax supports the following operators. Operators are grouped into levels of precedence, starting with the highest precedence operators:

OperatorSyntax
Sub expression( Expression )
New objectNew Typename
LiteralValue
IdentifierValue
Self objectSelf
Super objectSuper
Null valueNull
PiPi
TrueTrue
FalseFalse
MinumumMin ( Expression1 , Expression2 )
MaximumMax ( Expression1 , Expression2 )
MemberExpression . Identifier
IndexExpression [ IndexExpressions ]
CallExpression ( Parameters )
Negate- Expression
Posate+ Expression
Bitwise complement~ Expression
Boolean notNot Expression
Absolute valueAbs Expression
SignSgn Expression
Value byte sizeSizeOf Expression
Variable addressVarptr Variable
Convert type expressionType Expression
PowerExpression ^ Expression
MultiplyExpression * Expression
DivideExpression / Expression
RemainderExpression Mod Expression
Bitwise shift leftExpression Shl Expression
Bitwise shift rightExpression Shr Expression
Arithmetic shift rightExpression Sar Expression
AddExpression + Expression
SubtractExpression - Expression
Bitwise andExpression & Expression
Bitwise orExpression | Expression
Bitwise exclusive orExpression ~ Expression
EqualExpression = Expression
Not equalExpression <> Expression
Less thanExpression < Expression
Greater thanExpression > Expression
Less than or equalExpression <= Expression
Greater than or equalExpression >= Expression
Conditional andExpression And Expression
Conditional orExpression Or Expression

In addition, the following built in functions are also supported:
FunctionSyntax
Character codeAsc ( Expression )
CharacterChr ( Expression )
Value lengthLen ( Expression )

Null returns 0, an empty string, an empty array, the null object or a pointer to 0 depending on context.

True and False are integer constants with the values 1 and 0, respectively.

The index operator can be used on either arrays or strings. If used on an array, the element at the specified index is returned. If used on a string, the character code of the character at the specified index is returned.

The Not operator 'inverts' the logic of a boolean expression. If the expression evaluates to true, Not returns false and vice versa.

Asc returns the character value of the first character of a string, or -1 if the length of the string is 0.

Chr constructs a 1 character string with the specified character value.

Len can be used with either a string or array. When used with a string, Len returns the number of characters in the string. When used with an array, Len returns the number of elements in the array. In the case of multidimensional arrays, Len returns the total number of elements.

Boolean expressions

It is frequently necessary to consider an expression as 'true' or 'false', for example, for use with an If statement.

The rules for determining whether an expression is true or false are:

Expression TypeTruth condition
NumericTrue if value is not equal to 0
ObjectTrue if object is not equal to Null
StringTrue if length is not equal to 0
ArrayTrue if length is not equal to 0