ST Main Syntax
A Structured Text (ST) program is a list of ST statements. Each statement ends with a semi-colon (";") separator. Inactive or active separators separate names used in the source code (variable identifiers, constants, language keywords...). Inactive separators are space character, end of line or tab stops. Active separators have a well-defined significance, for example, the ">" separator indicates a "greater than" comparison.
Comments enable the inclusion of non-executed information throughout code. Insert comments anywhere in an ST program. Comments can run multiple lines and must begin with "(*" and end with "*)". Do not use interleave comments, for example, comments within comments.
When typing statements, a drop-down combo box lists the available items such as identifiers, operators, functions, and function blocks. Filter the listed items by typing letters, digits, and specific special characters: !, #, $, %, &, \, *, +, -, ,/ <, :, =, >, ?, @, \, ^, _, `, |, and ~.
These are basic types of ST statements:
- Assignment statement (variable := expression;)
- Function call
- Function block call
- Selection statements (IF, THEN, ELSE, CASE...)
- Iteration statements (FOR, WHILE, REPEAT...)
- Control statements (RETURN, EXIT...)
- Special statements for links with other languagesTIP: Use wired variables instead of directly represented variables. The compiler does not support a directly represented variable or a default wired variable after wiring the directly represented variable to a user-defined variable. For example, use _IO_QW1_1_10 instead of %QW1.1.10.
Basic coding is black while other items display using customizable colors for ST syntax. The default colors for ST elements are the following:
- Comments are green
- The Editor background is white
- Identifiers are black
- Numbers are firebrick
- Operators are black
- Program organization units (POUs) are blueviolet
- Punctuation marks are black
- Reserved words are fuchsia
- Strings of text are gray
Inactive separators between active separators, literals, and identifiers increase ST program legibility. The ST inactive separators are space (blank), tabs, and end of line. Place end of lines anywhere in a program. These rules apply to inactive separators:
- Write one statement on one line
- Use tabs to indent complex statements
- Insert comments to increase legibility of lines or paragraphs
Examples
Low Readability
imax := max_ite; cond := X12; if not(cond (* alarm *) then return; end_if; for i (* index *) := 1 to max_ite do if i <> 2 then Spcall(); end_if; end_for; (* no effect if alarm *)
High Readability
(* imax : number of iterations *) (* i: FOR statement index *) (* cond: process validity *) imax := max_ite; cond := X12; if not (cond) then return; end_if; (* process loop *) for i := 1 to max_ite do if i <> 2 then Spcall (); end_if; end_for;
Task | Procedure |
---|---|
Customize the default display settings for ST programs |
|
Customize the display settings for current ST program |
Customize the font for the required item by clicking ![]() Font dialog box displays allowing customization of the font, text size, bold, italic, strikeout, and underline styles.
|
Provide Feedback