1.3 Language Elements
1.3.1 Character set
- The Universal Coded Character Set (UCS) includes all other character sets. It guarantees bi-directional compatibility with other character sets, i.e., if user converts any text string to UCS format and then back to the original encoding, the user does not lose any information.The UCS contains all the characters of known languages.
- According to the national standard GB/T15969.3-2005, the text elements in the text and graphic programming language used by programmable controllers should be composed of 3-7 columns of characters according to the “Basic Code Table” in the programmable controllers and expressed as Chinese characters according to the “Basic Set of Chinese Character Set for Editing Characters for Information Exchange” in the standard GB2312-1980.
- Except for comments, string literals, and string variable values, uppercase and lowercase letters have the same meaning. For example, Control and CONTROL are the same variable name or identifier.
1.3.2 Identifier
- Identifier : A string of letters, numbers, and underscore characters, starting with a letter or underscore character. However, trailing underscores are not allowed, and the font and case of letters in identifiers have no meaning. At the same time, identifiers are not allowed to start with multiple underscores or multiple embedded consecutive underscores. In Baosky PLC namespaces, variables, GVS, PU, FB,FC, etc. follow this specification.
- Identifiers are used to name various variables, programs, configurations, resources, etc.
| Serial number | Feature description | Example |
|---|---|---|
| 1 | Uppercase letters and numbers | W4; ER8; RT8 |
| 2 | Uppercase and lowercase letters, numbers, embedded underscores | Var2; Var2_int; Var2_int_9; var1,var_int |
| 3 | Uppercase and lowercase letters, numbers, leading or embedded underscores | _Var2; _12_int |
1.3.3 Comments
-
Improve code readability: Comments can help other developers better understand the logic and intent of the code, saving time reading the code.
-
Convenient code maintenance: As the project iterates, the code may be changed and fixed. Good comments can help developers locate problems and make modifications more easily.
-
Comment related instructions are shown in the table below:
| Comment description | Example |
|---|---|
| Single line comment //... | x:=12; //Assign the value of variable x to 12 |
| Multi-line comments (*....*) | (*a:=10; b:=true;*) Comment two lines of code |
| Multi-line comments /*....*/ | /*a:=10; b:=true;*/ Comment two lines of code |
| Nested comments use (*..(*..*)..*) | (*(*b:=true;*)*) Nested comments |
| Nested comments use /*../*..*/..*/ | /*/*b:=true;*/*/ Nested comments |
1.3.4 Literal (constant)
- Literal: A literal is a value that represents the value of some constant. There are three types: numeric literal, string literal, and time literal. In computer science, a literal is a notation used to express a fixed value in source code.
- Numeric literal: defined as a decimal number or base number. In a given implementation, the maximum number of bits for each numeric literal is sufficient to represent the entire range of values of all data types represented by the literal.
- Numeric literals are divided into two categories: integer literals and real number literals. The base of integer literals is decimal, and can also be expressed in base 2 or 16. For integer literals with base 16, use the extended set of digits A through F, which represent decimal 10 through 15. The base number should not contain the prefix "+" or "-". They are interpreted as bit string literals. Real numerical values are distinguished by the presence of a decimal point.
- The characteristics and examples of digital direct quantities are as follows
| Serial number | Description | Example | Explanation |
|---|---|---|---|
| 1 | Integer literal | -12 123_4 +986 | 123_4 is equal to 1234 |
| 2 | Real literal | 0.0 0.369 3.141592_6 | 3.1415926 is equal to 3.141592_6 |
| 3 | Real literal expansion | -1.34E-12,-1.34e-12 1.0E+6,1.0e+6 1.334E6,1.334e6 | e (E) is not case sensitive + can be omitted |
| 4 | Binary literal | 2#1111_1111 2#1110_0000 | Binary all 1, represents decimal 255 Binary 111 represents decimal 224 |
| 5 | Hexadecimal literal | 16#FF or 16#ff 16#E0 or 16#e0 | Hexadecimal FF represents decimal 255 Hexadecimal E0 represents decimal 224 |
| 6 | Boolean 0 or 1 | Number 0 or 1 | |
| 7 | Boolean true or false | TRUE FALSE | |
| 8 | Type literal | INT#-12 WORD#16#AFF WORD#1234 1234=16#4D2 UINT#16#89AF CHAR #'A' BOOL#0 BOOL#1 BOOL#FALSE BOOL#TRUE |
-
String literal
- Single byte: Occupying one byte, a single-byte string literal is a sequence of zero or more characters, beginning or ending with a single quote character. In a single-byte string, the three-character combination of the dollar sign followed by two hexadecimal digits can be understood as the hexadecimal representation of the 8-bit character code.
- Single-byte string literals are shown in the following table:
Serial number Description Example 1 Null (zero length) '' 2 Char 'a' 3 Space ' ' 4 Single quotes '$'' 5 Dollar '$$' 7 Line break, input line '$L' or '$l' 8 New line '$N' or '$n' 9 Page change, input page '$P' or '$p' 10 Enter '$R' or '$r' 11 TAB key '$T' or '$t' 12 Supports single byte with $ character and two hexadecimal characters '$0A' 13 String STRING#'OK' 14 Character CHAR#'X' -
Time literal
-
Duration data shall be defined by the keywords T#, TIME#, or LTIME# on the left. Duration data shall support representation by days, hours, minutes, seconds and milliseconds (LTIME# supports nanoseconds), and any combination thereof, with units permitted to be separated by an underscore character, and units of time such as seconds, milliseconds, etc., may be represented by uppercase or lowercase letters.
-
The inherent elements of time direct literal are shown in the following table:
| Serial number | Description | Example |
|---|---|---|
| 1 | d | days |
| 2 | h | hours |
| 3 | m | minutes |
| 4 | s | seconds |
| 5 | ms | milliseconds |
| 6 | us | microseconds |
| 7 | ns | nanoseconds |
- The common expressions of time literal length and short prefixes are as shown in the following table:
| Serial number | Description | Example |
|---|---|---|
| 1 | Short prefix | T#14ms T#-14ms LT#14.7s T#14.7m T#14.7h t#14.7d t#25h15m t#5d14h12m18s35ms lt#12h4m34ms230us400ns |
| 2 | Short prefix (units separated by underscore character) | t#25h_15m t#5d_14h_12m_18s_35ms |
| 3 | Long prefix | TIME#14msTIME#-14ms time#14.7s LTIME#5m30s500ms100.1us |
| 4 | Long prefix (units are separated by underscore characters) | TIME#25h_15m ltime#5d_14h_12m_18s_3.5ms LTIME#34s_345ns |
- The common expressions of the literal length and short prefixes of time and date are as shown in the following table:
| Serial number | Description | Example |
|---|---|---|
| 1 | Date (long prefix) | DATE#1984-06-25 date#2010-09-22 |
| 2 | Date (short prefix) | D#1984-06-25 |
| 3 | Time (long prefix) | TIME_OF_DAY#12:36:45.32 |
| 4 | Time (short prefix) | TOD#15:15:15.36 |
| 5 | Time and date (long prefix) | DATE_AND_TIME#1956-03-14-12:56:22 |
| 6 | Time and date (short prefix) | DT#2021-03-25-14:56:23 |
Only the smallest unit does not support floating point numbers
1.3.5 Keywords
-
A keyword is a combination of offset characters that is used as a separate syntax element.
-
Includes: basic data types, language elements, etc.
-
Keywords are shown in the table below:
| Serial number | Description | Keywords |
|---|---|---|
| 1 | BOOL | BOOL |
| 2 | Byte | BYTE |
| 3 | Word | |
| 4 | Double word | DWORD |
| 5 | Long word | LWORD |
| 6 | Short integer type | SINT |
| 7 | Unsigned integer type | UINT |
| 8 | Integer type | INT |
| 9 | Unsigned integer type | UINT |
| 10 | Double Integer | DINT |
| 11 | Unsigned double | UDINT |
| 12 | Long Integer | LINT |
| 13 | Unsigned long | ULINT |
| 14 | real number | REAL |
| 15 | Long real number | LREAL |
| 16 | single-byte character | CHAR |
| 17 | String | STRING |
| 20 | Duration (ms) | TIME |
| 21 | Date | DATE |
| 22 | Day and time | TIME_OF_DAY |
| 23 | Date and time | TOD |
| 24 | Date and time | DATE_AND_TIME |
| 25 | Date and time | DT |
| 26 | Long time | LTIME |
| 32 | User-defined type | TYPE |
| 33 | Type end definition | END_TYPE |
| 34 | Array | ARRAY ARRAY |
| 35 | Array or CASE statement OF | OF |
| 58 | Logical true | TRUE |
| 59 | Logical false | FALSE |
| 60 | Start of variable segment within GVS | GLOBAL VARIABLE |
| 61 | Start of variable segment in PU | VAR |
| 62 | Start of temporary variable segment in PU | TEMP |
| 63 | Start of input variable section | INPUT |
| 64 | Start of output variable section | OUTPUT |
| 65 | Start of input and output variable section | INOUT |
| 66 | Start of variable segment within GVS | GLOBAL CONSTANT |
| 67 | Constant | LOCAL CONSTANT |
| 68 | Save variables after power off | RETAIN |
| 69 | Negate (find the complement code) | NOT |
| 70 | Modulo operation (representing the remainder when a is divided by b) | MOD |
| 71 | "AND" operation | AND |
| 72 | "XOR" operation | XOR |
| 73 | "OR" operation | OR |
| 74 | IF instruction | IF |
| 75 | Instruction part of the IF instruction | THEN |
| 76 | Selection conditions of IF instruction | ELSIF |
| 77 | Alternative branches in IF and CASE statements | ELSE |
| 78 | End IF instruction | END_IF |
| 79 | Introduction of CASE statement | CASE |
| 80 | End CASE statement | END_CASE |
| 81 | Introducing the FOR statement | FOR |
| 82 | Define the entire range of values for the FOR statement | TO |
| 83 | FOR loop increment | BY |
| 84 | Introducing the directive section in the FOR and WHILE directives | DO |
| 85 | End FOR statement | END_FOR |
| 86 | Introduction of REPEAT | statement REPEAT |
| 87 | End REPEAT | Instruction part of statement UNTIL |
| 88 | End REPEAT statement | END_REPEAT |
| 89 | Introduction of WHILE instruction | WHILE |
| 90 | End WHILE command | END_WHILE |
| 91 | Terminate the current program channel in the loop and enter the next loop | CONTINUE |
| 92 | Instruction to exit the loop | EXIT |
| 93 | Introduction of GOTO statement | GOTO |
| 94 | Exit this program unit | RETURN |
1.3.6 Delimiter
- Delimiters are used in “instructions” or statements to isolate, identify, etc. Commas are used to separate multiple variables; semicolons indicate the end of a one-day statement in ST;
- The explanation part of the program and statements is stored between asterisks + brackets (**); the colon plus the equal sign indicates assignments in ST programming statements, etc.
- Commonly used decomposition sets are shown in the following table:
| Delimiter | Application | Notes and examples |
|---|---|---|
| Space | Spaces can be inserted anywhere in the PLC program | Direct insertion of spaces in keywords, text, identifiers and enumeration values is not allowed |
| TAB | TAB can be inserted anywhere in the PLC program | Direct insertion of TAB in keywords, text, identifiers and enumeration values is not allowed |
| + | Decimal prefix symbol (positive number); Add operator | +456, +147; 22+78 |
| - | Prefix sign of decimal number (negative number); Year-month-day separator; Subtraction operator | -753; D#2024-05-13; 15-2 |
| # | Base number delimiter; Data type delimiter; Time literal delimiter | 2#1110; SINT15; T#20ms |
| . | Separator for positive numbers and decimals; Hierarchical addressing address character; Structure element separator; Function block instance structure separator; Global namespace ;Namespace delimiter | 3.14; IABC.3//IBC is a bit string data type; Channel[0].type/abc.number; TON1.Q; SYS .SR |
| E/e | Exponent delimiter | 1.0e+6 |
| ' ' | String start/end character | 'HelloWorld' |
| $ | The beginning of special characters in the string | '$L' means line feed; '$R' means carriage return |
| : | Time text delimiter; Variable/type delimiter | TOD#12:41:21.11; Test: INT |
| := | Input variable connection operator; Assignment operator | INT_1(SINGLE:=Z2,PRIORITY:=1) |
| () | Subrange section break; Initialization repetition factor; Instruction list modifier; Function argument; Subexpression classification; Function block Input table delimiter | DATA:INT(-100..100); ARRAY[1..2,1..3] OF INT:=1,2,3(4),6; (A>B); ARlimit(Var1); (a(b-c)+d);< br/>TON_1(IN:=a,PT:=T#5m) |
| [] | Array subscript delimiter | ARRAY[1..2,1..3] OF INT; MMOD_5_CFG.CH[5].Range:=BI_10V |
| , | Array subscript delimiter; Function block initial value delimiter; Function block input table delimiter; Function argument table delimiter; Case to table delimiter Symbol | ARRAY[1..2,1..3] OF INT := 1,2,3(4),6; TON_1(IN:A,pt:=50ms) SR_1(S1:=A,REAL:=B); LIMIT(MN:=4,IN=A,MX:=20) CASETEP OF 1,5:DISPLAY:=FALSE |
| ; | Statement separator | a:=15 |
| .. | Array range delimiter; Subrange; Case range delimiter | ARRAR[1..2]; DATA:INT(-1000..1000); CASETEPOF(1..5):display:=FALSE |
| % | Directly represents the prefix of the variable | %IW0 |
| => | Output connection operator | C10(CU:=iNPUT, Q=>Out) |