Literals
Integer Literals
Decimal
| 18
|
Binary
| 2#10010
|
Octal
| 8#22
|
Hexadecimal
| 16#12
|
The same integer value in decimal, binary, octal and hexadecimal notation.
Real Literals
Notation of real values
1.0
1.602E-19
Boolean Literals
Notation of Boolean values
0
1
TRUE
FALSE
Typed Literals
<typename>#<literal>
Typed literals where typename is a native type (e.g. Word or LReal) or an enumeration type (to avoid ambiguities).
Typing of literals is typically not necessary in GST, since the interpreter implements a decent typesystem that handles untyped literals properly. There are a few exceptions where the type of a literal is significant for semantics, like in the following example.
Example:
The first assignment assigns the value 16#80 to w, whereas the second one assigns the value 16#8000 to w.
{
VAR w: word; END_VAR
w := ror(BYTE#1,1);
w := ror(WORD#1,1);
}
String Literals
"abc"
'abc'
Notation of a 2-byte and a 1-byte string, respectively. Note that there is no implicit conversion between both types. The following escape-sequences can be used within both types of literals:
| line feed
|
| newline
|
| form feed
|
| carriage return
|
| tab
|
| quotes
|
| character of given code
|
.
Duration Literals
T#[+/-]<value><unit>[…]<value><unit>
TIME#[+/-] <value><unit>[…]<value><unit>
LT#[+/-]<value><unit>[…]<value><unit>
LTIME#[+/-]<value><unit>[…]<value><unit>
Time literals of type TIME or LTIME. The literal consists of an optional sign (+/-) and a sequence of value/ unit pairs. Value must be an integer, except for the last one that may also be a floating point number. Values must not be negative and may be arbitraryly large. Units must appear in the following order.
| day
|
| hour
|
| minute
|
| second
|
| millisecond
|
| microsecond
|
| nanosecond
|
An arbitrary subset of units may be used in a literal. For instance, the literal T#1d15ms1500.01us is valid.
Date Literals
DATE#<yyyy>-<mm>-<dd>
D#<yyyy>-<mm>-<dd>
LDATE#<yyyy>-<mm>-<dd>
LD#<yyyy>-<mm>-<dd>
Date literal of type DATE or LDATE. The literal is interpreted as UTC, i.e. timezone, daylight saving time and leap seconds are not considered. The year must not be smaller than 1970. The values yyyy, mm and dd have to be integer values, i.e. D#1980-20-10 is a valid date literal, for example.
Time-of-Day Literals
TIME_OF_DAY#<hh>:<mm>:<ss>
TOD#<hh>:<mm>:<ss>
LTIME_OF_DAY#<hh>:<mm>:<ss>
LTOD#<hh>:<mm>:<ss>
Time-of-day literal of type TOD or LTOD. The literal is interpreted as UTC, i.e. timezone, daylight saving time and leap seconds are not considered. hh and mm must be integer values. ss may be an integer or a floatingpoint number, i.e. TOD#7:30:3.1415 is a valid literal, for example.
Date-and-Time Literals
DATE_AND_TIME#<yyyy>-<mm>-<dd>-<hh>:<mm>:<ss>
DT#<yyyy>-<mm>-<dd>-<hh>:<mm>:<ss>
LDATE_AND_TIME#<yyyy>-<mm>-<dd>-<hh>:<mm>:<ss>
LDT#<yyyy>-<mm>-<dd>-<hh>:<mm>:<ss>
Date-and-time literal of type DT or LDT. The literal is interpreted as UTC, i.e. timezone, daylight saving time and leap seconds are not considered. This literal is a combination of the date literal and the time-of-day literal. Analogously, the corresponding rules for these two parts apply.