Skip to main content

6.2.2 ST Language syntax

6.2.2.1 ST Language

  • ST language operators are shown in the following table:
Serial numberOperator descriptionSymbolExamplePrecedence
1Brackets()(A+B/C)1(Highest)
2Call a function with return valueFunction name (parameter list)MAX(X,Y)2
3Dereference^R^3
4One dollar off--A4
5One dollar plus++A4
6Negation (find the complement code)NOTNOT C4
7Power operation**A**B5
8Multiplication*A*B6
9Division/A/B6
10Modular operationMODA MOD B6
11Addition+A+B+C7
12Subtraction-A-B-C7
13Compare sizes<
A<B8
14Comparison of equality=A=B8
15Is the comparison unequal<>A<>B8
16"AND" operation&
AND
A&B
A AND B
9
17"XOR" operationXORA XOR B10
18"OR" operationORA OR B11

Expression

  • Expression: The expression will be evaluated during the execution of the program and then return a value. An expression consists of operands (constants, variables, constants, or function calls) and their matching operators (such as *, /, +, or -). Operators allow expressions to be joined together or nested within each other
  • The order of operations is the precedence of the relevant operators, the order from left to right, and the parentheses
Arithmetic expression
  • An arithmetic expression can be either a numeric value or a combination of two values or expressions with arithmetic operators. Arithmetic expressions can handle various data types supported by the current CPU

The data types supported by arithmetic expressions are shown in the following table:

OperationOperatorFirst operandSecond operandResult
Power operation**Floating point number/integer //BaseInteger/Floating point number //ExponentFloating point number
One dollar plus or one dollar minus+ or -integer/floating point number
TIME/LTIME
-integer/floating point number
TIME/LTIME
Multiplication*Integer/Floating point number
TIME/LTIME
Integer/Floating point number
Integer
Integer/Floating point number
TIME/LTIME
Division/Integer/Floating point number
TIME/LTIME
Integer/Floating point number (not equal to 0)
Integer
Integer/Floating point number
TIME/LTIME
Modular operationMODIntegerIntegerInteger
Addition or subtraction+ or -integer/floating point
TIME
LTIME
TOD
DATE
DT
LTOD
LDATE<br/ >LDT
Integer/Floating point
TI ME,DINT(INT,UINT,SINT,USINT)
LTIME(TIME),LINT(DINT,UDINT,INT,UINT,SINT,USINT)
TIME,DINT(INT,UINT,S INT,USINT)
DINT(INT,UINT,SINT,USINT)
DINT(INT,UINT,SINT,USINT)
LTIME,LINT(DINT,UDINT,INT,UINT ,SINT,USINT)
LINT(DINT,UDINT,INT,UINT,SINT,USINT)
LTIME,LINT(DINT,UDINT,INT,UINT,SINT,USINT)
Integer/floating point
TIME
LTIME
TOD
DATE
DT
LTOD
LDATE
LDT
Subtraction-TOD
DATE
DT
LTOD
LDATE
LDT
TOD
DATE
DT<br/ >LTOD
LDATE,DATE
LDT
TIME
DINT
DINT
LTIME
LINT
LTINE
Relational expression
  • A relational expression compares the values or data types of two operands and returns a Boolean value. If the comparison is true, the result is TRUE otherwise FALSE
  • The data types supported by relational expressions are shown in the following table:
OperationOperatorFirst operandSecond operandResult
Comparison:
Equal, not equal
=,<>Integer/Floating point
Bit string
String
TIME, LTIME
Date and time
Integer/Floating point
Bit string
String
TIME, LTIME
Date and time
BOOL
Comparison:
Less than, less than or equal to, greater than, greater than or equal to
<,≤,>,≥Integer/floating point number
Bit string
String
TIME, LTIME
Date and time
Integer/floating point
Bit string
String
TIME, LTIME
Date and time
BOOL
  • When comparing floating-point numbers, specific data patterns for invalid floating-point numbers (NaN) that result in invalid operations (e.g., the square root of -1) are not comparable
  • STRING comparison compares UTF-8 encoded characters; WSTRING comparison compares UTF-16 encoded characters. During the comparison process, the length of the variable and the corresponding value of each character will be compared
  • Only two time data of the same data type can be compared. The system cannot compare invalid date and time data patterns
  • If two variables have the same structured data type, the values of the two structured operands can be compared (T3 supports this operation)
  • To compare two variables of ARRAY data type, the operator can only be "=" or "< >". And the following requirements must be met: (T3 supports this operation)
    • The data types of the elements must be the same
    • The dimensions of the two ARRAYs must be the same
    • The number of elements in all dimensions must be the same, but the specific ARRAY limits (starting subscripts) do not need to be the same
    • Supports STRUCT arrays, but does not support FB type arrays
  • 2 bit string size comparisons, the comparison is the comparison of the size of the bit strings corresponding to positive integer values. The bitstring data type can be compared with positive integers. But comparison with negative numbers is not allowed
Logical expression
  • A logical expression consists of two operands and a logical operator (AND, OR, XOR) or negation operand (NOT)
warning
  • If both operands are of BOOL data type, the result of the logical expression is also of BOOL data type
  • If at least one of the two operands is a bit string, the result is a bit string and the result is determined by the type of the highest operand
  • The data types supported by logical expressions are shown in the following table:
OperationOperatorFirst operandSecond operandResult
Negation (reverse code)NOTBOOL
bit string
-
-
BOOL
bit string
"AND" operationAND or &BOOL
bit string
BOOL
bit string
BOOL
bit string
"OR" operationORBOOL
bit string
BOOL
bit string
BOOL
bit string
"XOR" operationXORBOOL
bit string
BOOL
bit string
BOOL
bit string
Data type of untyped constant
  • Untyped constants follow the implicit conversion of expression data types. When the constant is an integer, it can be followed by an integer variable or a floating-point variable (or a typed constant) Perform invisible transformation. The result of the operation is "strongly typed" (deterministic type)

6.2.2.2 ST Programming

  • Programming window alt text
  • Programming window components:
PartMeaning
SidebarUser can set bookmarks and breakpoints in the sidebar
Line numberThe line number is displayed to the left of the program code
Outline viewThe corresponding code section will be highlighted in the outline view
Code areaIn the code area, ST programs can be edited
Display of absolute operandsThe symbolic operands assigned to absolute addresses are listed in this table