2 semantics of expressions, 1 order of evaluation, Simple assignment – ElmoMC Multi-Axis Motion Controller-Maestro User Manual

Page 85: Order of evaluation

Advertising
background image

5.4.2

Semantics of Expressions

This section explains when, and in what order, expressions are evaluated.

5.4.2.1

Maestro

Software Manual

MAXL Program Language

MAN-MASSW (Ver. Q)

Order of Evaluation

This section discusses the order in which expressions are evaluated but does not
explain the syntax or the semantics of the operators in these expressions.

Consider this example:

function run()
int a , b , c, res1, res2, res3
a = 2
b = 4
c = 9
res1 = a + b * c
res2 = a + (b * c)
res3 = (a + b) * c
end function

The output from the preceding code is:

res1 = 38
res2 = 38
res3 = 54

The order in which the res1 is evaluated is determined by the precedence and
associativity of the operators:

1. Multiplication (*) has the highest precedence in this expression; hence the

sub expression b * c is evaluated first.

2. Addition (+) has the next highest precedence, so a is added to the product of

b

and c.

3. Assignment operator (=) has the lowest precedence in the expression.

When parentheses are used to group the sub expressions, they alter the precedence
and also the order in which the expression is evaluated

5-23

Advertising