Structured text main syntax

A structured text (ST) program is a list of ST statements.
The following rules apply to the ST program statements:
  • Each statement ends with a semi-colon (";") separator.
  • Names used in the source code, such as variables, identifiers, constants, or language keywords, are separated with:
    • An inactive separator, such as a space
    • An active separator, such as ">", which indicates a "greater than" comparison
  • Comments are non-executed information and can be included anywhere in an ST program. Insert comments at the beginning of a line or after code using the following syntaxes:
    • Single-line comments begin with "//" and end at the end of the line.
    • Multi-line comments begin with "(*" and end with "*)".
    • Multi-line comments begin with "/*" and end with "*/".
TIP: Indirect bit addressing  is supported when a DINT variable or a defined word is used to specify the bit number.

ST statement types

Assignment statement
variable := expression;
Function call
  • (*Non-formal syntax with all inputs separated by commas in set order and output as a separate statement.*) Output1 := FUNCTION_NAME(Input1, Input2);
  • (*Formal syntax with inputs and outputs separated by comma optionally listed and in any order.*) Output1 := FUNCTION_NAME(InputParameter1 := Input1, InputParameter2 := Input2);
Function block call
  • (*Non-formal syntax with all inputs separated by commas in set order and output as a separate statement.*) FUNCTION_BLOCK_INSTANCE(Input1, Input2, ...); Output1 := FUNCTION_BLOCK_INSTANCE.OutputParameter1; Output2 := FUNCTION_BLOCK_INSTANCE.OutputParameter2;
  • (*Formal syntax with inputs and outputs separated by comma optionally listed and in any order.*) FUNCTION_BLOCK_INSTANCE(InputParameter1 := Input1, InputParameter2 := Input2, OutputParameter1 => Output1, OutputParameter2 => Output2);
Selection statements
IF, THEN, ELSE, CASE...
Iteration statements
FOR, WHILE, REPEAT...
Control statements
RETURN, EXIT...
Special statements
Use special statements to link with other languages.
  • In the ST language editor, items displayed in different colors:
    • Black: Basic code, numbers, and strings of text
    • Blue: Keywords and functions
    • Green: Comments
    • Red: Variables and function block instances
  • The inclusion of inactive separators between active separators, literals, and identifiers increases ST program legibility. ST inactive separators include:
    • Space - blank
    • Tabs
    • End of line - can be placed anywhere in a program
  • Guidelines for using inactive separators:
    • Write no more than one statement for each line.
    • Use tabs to indent complex statements.
    • Insert comments to increase legibility of lines or paragraphs.
Provide Feedback
Have questions or feedback about this documentation? Please submit your feedback here.
Normal