User manual

222
mikoBasic PRO for PIC32
MikroElektronika
Expressions
An expression is a sequence of operators, operands and punctuators that returns a value.
The primary expressions include: literals, constants, variables and function calls. From them, using operators, more
complex expressions can be created. Formally, expressions are dened recursively: subexpressions can be nested up
to the limits of memory.
Expressions are evaluated according to certain conversion, grouping, associativity and precedence rules which depend
on the operators in use, presence of parentheses and data types of the operands. The precedence and associativity of
the operators are summarized in Operator Precedence and Associativity. The way operands and subexpressions are
grouped does not necessarily specify the actual order in which they are evaluated by mikroBasic PRO for PIC32.
Expression Evaluation
General Rule
Expression are evaluated according to the right side operands. Operations are done at higher operand level, with
signed operands taking precedence.
Example:
a as byte
b as word
c as integer
a * b ‘ word level
a * c ‘ integer level
b * c ‘ integer level
Left side exception
In arithmetic expression left side is considered in the following manner: If the left side size in bytes is greater than higher
operand size, then evaluation is done at one level above higher operand level (to get correct calculations).
Example:
a as longword
b as byte
a = b * 5 ‘ this is done at word level
Conditional expressions
Conditional expressions may differ from the same code in assignment expressions (due to left side exception).
Example:
a as longword
b as byte