Closed BjAlvestad closed 1 year ago
Suggestion to try out
Add terminal factors for digits:
terminal fragment DECIMAL_DIGIT /([0-9](_[0-9])?)+/
terminal fragment BINARY_DIGIT /2#([0-1](_[0-1)?)+/
terminal fragment OCTAL_DIGIT /8#([0-7](_[0-7)?)+/
terminal fragment HEX_DIGIT /16#([0-9a-fA-F](_[0-9a-fA-F)?)+/
Add terminal factors for exponent;
terminal fragment EXPONENT /[eE][+-]?DECIMAL_DIGIT/
And terminal for Integer literal and Real number:
terminal INTEGER /[+-]?DECIMAL_DIGIT|BINARY_DIGIT|OCTAL_DIGIT|HEX_DIGIT/
terminal REAL /[+-]?((DECIMAL_DIGIT\\.DECIMAL_DIGIT)|(DECIMAL_DIGIT(\\.DECIMAL_DIGIT)?EXPONENT))/
Landed on
terminal fragment BINARY_DIGIT: /2#([0-1](_[0-1])?)+/;
terminal fragment OCTAL_DIGIT: /8#([0-7](_[0-7])?)+/;
terminal fragment HEX_DIGIT: /16#([0-9a-fA-F](_[0-9a-fA-F])?)+/;
terminal fragment DECIMAL_DIGIT: /([0-9](_[0-9])?)+/;
terminal fragment EXPONENT: /[eE][+-]?/DECIMAL_DIGIT;
terminal REAL: /[+-]?/((DECIMAL_DIGIT('.'DECIMAL_DIGIT)?EXPONENT)|(DECIMAL_DIGIT'.'DECIMAL_DIGIT));
terminal INTEGER: /[+-]?/BINARY_DIGIT|OCTAL_DIGIT|HEX_DIGIT|DECIMAL_DIGIT;
Ref. section 11.3 of SCLV4_e
Examples of valid formats for decimal digit strings in literals:
1000
1_120_200
666_999_400_311
Integer literals
Integer literals can be assigned to
BOOL
,BYTE
,INT
,DINT
,WORD
,DWORD
(depending on their length).Integer literals can also be specified in binary, octal or hexadecimal with the prefixes
2#
,8#
and16#
Real number literals
This is nubers with decimal places, and can only be assigned to the
REAL
data type.Note that eksponent is denoted with
e
followed by+
,-
or just a number directly. E.g.3.0E+10
,3.0E10
,3e+10
,3E10
,0.3E+11
,0.3e11
,30.0E+9
,30e9
are all representing 3*10^10.Summary of various alternatives