Primary Expressions¶
Overview¶
Primary expressions are the most basic units of expressions.
Syntax¶
true
false
123
0xff
123u
12.34
'c'
'\n'
"hello world"
someIdentifier
_another_one
someFunctionName
(1 + 2)
[Point]
Rules¶
Boolean Literals¶
Boolean literals true and false MUST be supported. The literal true MUST evaluate to exactly 1. The literal false MUST evaluate to exactly 0. The bool type MUST have an 8-bit representation with exactly two valid values: 0 (false) and 1 (true).
Integer Literals¶
Both decimal and hexadecimal integer literals MUST be supported and of int type. A lowercase or uppercase u (or U) MUST be supported as a suffix to denote unsigned integer literals (which SHOULD be uint type). Literals which do not fit within their types (int or uint) MUST result in a compile time error.
Float Literals¶
Floating point literals MUST be supported and of float type. A lowercase or uppercase d (or D) MUST be supported as a suffix to denote floating point literals with a type of double (double precision floating point type). A lowercase or uppercase h (or H) MUST be supported as a suffix to denote floating point literals with a type of half (half precision floating point type).
Char Literals¶
Character literals MUST be supported and of type uchar. A character literal MUST represent a single byte value.
The following escape sequences MUST be supported in character literals:
\\: backslash\': single quote\n: line feed (U+000A)\r: carriage return (U+000D)\t: horizontal tab (U+0009)\0: null character (U+0000)\xHH: byte with hexadecimal valueHH(exactly two hexadecimal digits)
A byte value that overflows the range of uchar (0 to 255) MUST result in a compile-time error.
String Literals¶
String literals MUST be supported and of type read []uchar. A string literal MUST evaluate to a read capability for a statically allocated, immutable string whose contents exactly match the literal, with escape sequences fully substituted. The statically allocated string MUST include a null terminator. The resulting slice capability MUST cover the entire statically allocated string, from the first to the last character (excluding the null terminator).
The following escape sequences MUST be supported in string literals:
\\: backslash\": double quote\n: line feed (U+000A)\r: carriage return (U+000D)\t: horizontal tab (U+0009)\0: null character (U+0000)\xHH: byte with hexadecimal valueHH(exactly two hexadecimal digits)
A byte value that overflows the range of uchar (0 to 255) MUST result in a compile-time error.
Identifiers¶
Identifiers MUST be supported. Identifiers MUST evaluate to a local or global symbol of the same name (case sensitive). If no symbol exists, an error MUST be shown. A bare function name used as an expression MUST evaluate to a function pointer value for that function.
Null Handle Literal¶
The expression [T] MUST evaluate to a null handle of type &T. A null handle literal MUST NOT allocate any memory. When [ is not immediately preceded by an expression (a variable, function call, field access, or index expression), it MUST be parsed as a null handle literal. When [ follows an expression, it MUST be parsed as the index operator.
Parentheses¶
Parenthesised expressions MUST be supported and MUST evaluate to their contents. If no contents exist, a compile-time error MUST be shown.