An expression is a construction which after its evaluation returns a value. This value is used in instructions.
Expressions are composed of operators, operands, and/or assignments. An operand can be a constant, a variable, a function call, or another expression.
Examples
33 |
(* Constant *) |
ivar |
(* Variable *) |
fct(a,b,c) |
(* Function call*) |
a AND b |
(* Expression *) |
(x*y) / z |
(* Expression *) |
real_var2 := int_var; |
(* Assignment, see below *) |
The evaluation of an expression is performed by processing the operators according to certain rules. The operator with the highest order of operation is processed first, then the operator with the next operating level, and so on, until all operators have been processed.
Below you find a table of the ST operators in the order of their ordinal operating level:
Operation |
Symbol |
Operating Level |
---|---|---|
placed in parentheses |
(expression) |
highest order |
function call |
function name (parameter list) |
.............. |
exponentiation |
EXPT |
............. |
negate |
– |
............ |
building of complements |
NOT |
........... |
multiply |
* |
.......... |
divide |
/ |
......... |
modulo |
MOD |
........ |
add |
+ |
....... |
subtract |
– |
...... |
compare V |
<,>,<=,>= |
..... |
equal to |
= |
.... |
not equal to |
<> |
... |
boolean AND |
AND |
.. |
boolean XOR |
XOR |
. |
boolean OR |
OR |
lowest order |
As an extension to the IEC 61131-3 standard (ExST), assignments can be used as an expression.
Examples:
|
|
---|---|
int_var1 := int_var2 := int_var3 + 9; |
(* int_var1 and int_var2 both equal to the value of int_var3 + 9*) |
real_var1 := real_var2 := int_var; |
(* correct assignments, real_var1 and real_var2 will get the value of int_var *) |
int_var := real_var1 := int_var; |
(* a message will be displayed due to type mismatch real-int *) |
IF b := (i = 1) THEN |
(*Expression used inside of IF condition statement: First b will be assigned TRUE or FALSE, depending on whether i is 1 or not, then the result value of b will be evaluated.*) |