Expressions

Operators

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

Operator Syntax
Subexpression (Expression)
New Object New Expression
Literal Value
Identifier Value
Self Object Self
Super Object Super
Null value Null
Pi Pi
True True
False False


Member access Expression.Expression
Index Expression[Subscripts]
Invoke Expression(Parameters)


Negate - Expression
Posate + Expression
Bitwise complement ~ Expression
Boolean not Not Expression
Absolute value Abs Expression
Sign Sgn Expression
Character code value Asc Expression
Character Chr Expression
Length of value Len Expression
Size of value in bytes SizeOf Expression
Address of variable VarPtr Expression
Convert type Type Expression


Mulitply Expression * Expression
Divide Expression / Expression
Remainder Expression Mod Expression
Bitwise shift left Expression Shl Expression
Bitwise shift right Expression Shr Expression
Arithmetic shift right Expression Sar Expression


Add Expression + Expression
Subtract Expression - Expression


Bitwise and Expression & Expression
Bitwise or Expression | Expression
Bitwise exclusive orExpression ~ Expression


Equal Expression = Expression
Not equal Expression <> Expression
Less than Expression < Expression
Greater than Expression > Expression
Less than or equal Expression <= Expression
Greater than or equal Expression >= Expression


Conditional and Expression And Expression
Conditional or Expression Or 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...Then statement.

BlitzMax achieves this by comparing an expression with Null. If the expression is not equal to Null, then the expression is considered to be true, otherwise the expression is considered to be false.

Therefore, the general rules for determining whether an expression is true or false are:

Expression type Truth condition
Numeric True if value is not equal to 0
String or array True if length is not equal to 0
Object True if object is not equal to the null object
Pointer True if pointer is not equal to 0