Operators

Operators

Structured Text expressions are built from operators acting on typed operands. The same operator symbol can apply to multiple types (+ for INT and for REAL), but operand types must match exactly — there is no implicit promotion across families.

Sub-pages

  • Arithmetic+, -, *, /, MOD, **.
  • BitwiseAND, OR, XOR, NOT. Note these same keywords are also the logical operators when applied to BOOL; the distinction is operand-type.
  • Comparison=, <>, <, <=, >, >=.
  • Assignment + precedence:= and the full operator-precedence table (highest to lowest).

Quick reference: precedence table

From highest to lowest binding strength. Operators of the same precedence associate left-to-right (except ** which is right-associative).

ClassOperatorsNotes
Parentheses(...)Highest — overrides everything
Function callname(...)Includes FB instance call
Exponent**Right-associative
Unary- (negation), NOTUnary minus, logical/bitwise NOT
Multiplicative*, /, MOD
Additive+, -
Comparison<, <=, >, >=
Equality=, <>
Bitwise/Logical ANDAND, && and AND synonymous
Bitwise/Logical XORXOR
Bitwise/Logical ORORLowest binding strength

AND / OR / XOR / NOT are simultaneously logical (when both operands are BOOL) and bitwise (when both are BYTE / WORD / DWORD / LWORD). Mixing a BOOL and a BYTE is a type error — use BOOL_TO_BYTE / BYTE_TO_BOOL to convert explicitly.

IEC reference

IEC 61131-3 third edition (2013), clause 6.6.1 — “Operators of the ST language”.

ForgeIEC notes

The editor’s tree-sitter highlighter colours the operator keywords distinctly from other identifiers. Auto-completion will not suggest type-incompatible operands.