ST Main Syntax
A Structured Text (ST) program is a list of ST statements. Each statement ends with a semi-colon (";") separator. Names used in the source code (variable identifiers, constants, language keywords...) are separated with inactive separators (space character, end of line or tab stops) or by active separators, which 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 automatically lists the available items such as identifiers, operators, functions, and function blocks. The listed items are focused by typing letters, digits, and underscore characters.
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 languages
When entering ST syntax, basic coding is black while other items are displayed using customizable colors. The default colors for ST elements are:
- Comments are green
- The Editor background is white
- Identifiers are black
- Numbers are firebrick
- Operators are black
- Program organization units (POUs) are blue-violet
- 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. ST inactive separators are: space (blank), tabs and end of line. Place end of lines anywhere in a program. These rules apply to using inactive separators:
- Write one statement on one line
- Use tabs to indent complex statements
- Insert comments to increase legibility of lines or paragraphs
Example
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 the current ST program |
|
Provide Feedback