' is optional in type suffixes for numerical literals

This commit is contained in:
Araq 2012-07-02 08:49:38 +02:00
commit 2e2650c708
6 changed files with 51 additions and 16 deletions

View file

@ -42,6 +42,7 @@ primary ::= primaryPrefix* (symbol [generalizedLit] |
generalizedLit ::= GENERALIZED_STR_LIT | GENERALIZED_TRIPLESTR_LIT
literal ::= INT_LIT | INT8_LIT | INT16_LIT | INT32_LIT | INT64_LIT
| UINT_LIT | UINT8_LIT | UINT16_LIT | UINT32_LIT | UINT64_LIT
| FLOAT_LIT | FLOAT32_LIT | FLOAT64_LIT
| STR_LIT | RSTR_LIT | TRIPLESTR_LIT
| CHAR_LIT

View file

@ -303,20 +303,33 @@ Numerical constants
hexdigit ::= digit | 'A'..'F' | 'a'..'f'
octdigit ::= '0'..'7'
bindigit ::= '0'..'1'
INT_LIT ::= digit ( ['_'] digit )*
| '0' ('x' | 'X' ) hexdigit ( ['_'] hexdigit )*
| '0o' octdigit ( ['_'] octdigit )*
| '0' ('b' | 'B' ) bindigit ( ['_'] bindigit )*
HEX_LIT ::= '0' ('x' | 'X' ) hexdigit ( ['_'] hexdigit )*
DEC_LIT ::= digit ( ['_'] digit )*
OCT_LIT ::= '0o' octdigit ( ['_'] octdigit )*
BIN_LIT ::= '0' ('b' | 'B' ) bindigit ( ['_'] bindigit )*
INT_LIT ::= HEX_LIT
| DEC_LIT
| OCT_LIT
| BIN_LIT
INT8_LIT ::= INT_LIT '\'' ('i' | 'I' ) '8'
INT16_LIT ::= INT_LIT '\'' ('i' | 'I' ) '16'
INT32_LIT ::= INT_LIT '\'' ('i' | 'I' ) '32'
INT64_LIT ::= INT_LIT '\'' ('i' | 'I' ) '64'
INT8_LIT ::= INT_LIT ['\''] ('i' | 'I') '8'
INT16_LIT ::= INT_LIT ['\''] ('i' | 'I') '16'
INT32_LIT ::= INT_LIT ['\''] ('i' | 'I') '32'
INT64_LIT ::= INT_LIT ['\''] ('i' | 'I') '64'
UINT8_LIT ::= INT_LIT ['\''] ('u' | 'U')
UINT8_LIT ::= INT_LIT ['\''] ('u' | 'U') '8'
UINT16_LIT ::= INT_LIT ['\''] ('u' | 'U') '16'
UINT32_LIT ::= INT_LIT ['\''] ('u' | 'U') '32'
UINT64_LIT ::= INT_LIT ['\''] ('u' | 'U') '64'
exponent ::= ('e' | 'E' ) ['+' | '-'] digit ( ['_'] digit )*
FLOAT_LIT ::= digit (['_'] digit)* ('.' (['_'] digit)* [exponent] |exponent)
FLOAT32_LIT ::= ( FLOAT_LIT | INT_LIT ) '\'' ('f' | 'F') '32'
FLOAT64_LIT ::= ( FLOAT_LIT | INT_LIT ) '\'' ('f' | 'F') '64'
FLOAT32_LIT ::= HEX_LIT '\'' ('f'|'F') '32'
| (FLOAT_LIT | DEC_LIT | OCT_LIT | BIN_LIT) ['\''] ('f'|'F') '32'
FLOAT64_LIT ::= HEX_LIT '\'' ('f'|'F') '64'
| (FLOAT_LIT | DEC_LIT | OCT_LIT | BIN_LIT) ['\''] ('f'|'F') '64'
As can be seen in the productions, numerical constants can contain underscores
@ -328,7 +341,10 @@ There exists a literal for each numerical type that is
defined. The suffix starting with an apostrophe ('\'') is called a
`type suffix`:idx:. Literals without a type suffix are of the type ``int``,
unless the literal contains a dot or ``E|e`` in which case it is of
type ``float``.
type ``float``. For notational convenience the apostrophe of a type suffix
is optional if it is not ambiguous (only hexadecimal floating point literals
can be ambiguous).
The type suffixes are:
@ -338,7 +354,12 @@ The type suffixes are:
``'i8`` int8
``'i16`` int16
``'i32`` int32
``'i64`` int64
``'i64`` int64
``'u`` uint
``'u8`` uint8
``'u16`` uint16
``'u32`` uint32
``'u64`` uint64
``'f32`` float32
``'f64`` float64
================= =========================
@ -3114,6 +3135,10 @@ arguments. If none of its parameters have the type ``var T``
or ``ref T`` or ``ptr T`` this means no locations are modified. It is a static
error to mark a proc/iterator to have no side effect if the compiler cannot
verify this.
As a special semantic rule, the built-in ``echo`` pretends to be free of
side effects, so that it can be used for debugging routines marked as
``noSideEffect``.
**Future directions**: ``func`` may become a keyword and syntactic sugar for a
proc with no side effects: