Expressions and parentheses
Structured text (ST) expressions consist of operators and their operands. An operand might be a constant (literal) value, a control variable, or another expression (or sub-expression).
For each single expression, which combines operands with one ST operator, the type of the operands must match. A single expression has the same data type as its operands and can be used in a more complex expression.
Example 1
Example | Result |
---|---|
(boo_var1 AND boo_var2) | BOOL type |
not (boo_var1) | BOOL type |
(sin (3.14) + 0.72) | REAL type |
(t#1s23 + 1.78) | Invalid expression |
Parentheses are used to isolate subcomponents of an expression and to explicitly order the priority of operations. When no parentheses are given for a complex expression, the operation sequence is implicitly given by the default priority between the ST operators.
Example 2
Example | Result | Description |
---|---|---|
2 + 3 * 6 | Equals 2+18=20 | Multiplication operator has a higher priority |
(2 + 3) * 6 | Equals 5*6=30 | Expressions in parentheses take precedence |
Provide Feedback