1.6 KiB
1.6 KiB
| Title | Prev | Next |
|---|---|---|
| 2 Lexical Structure | Overview | Primitive Types |
2. Lexical Structure
2.1 Comments
// Single-line comment
2.2 Identifiers
Regular Identifiers
- Start with letter or underscore:
[a-zA-Z_][a-zA-Z0-9_]* - Case-sensitive
- When encountered, identifiers are executed immediately
Identifier Literals
- Prefix with
::to push the identifier itself onto the stack instead of executing it - Syntax:
::namepushes the identifiernameas a value - Example:
::Addablepushes the identifierAddableonto the stack - Example:
::Pointpushes the identifierPointonto the stack
Advanced Usage: See Section 11.2 for complete identifier literal rules and context-dependent behavior.
2.3 Literals
Integer Literals
42 // i64 (default)
42:i32 // Annotate as i32
0xFF // hexadecimal
0b1010 // binary
Floating Point Literals
3.14 // f64 (default)
3.14:f32 // Annotate as f32
String Literals
"hello world"
"escape sequences: \n \t \\ \""
Escape Sequences
\n- Newline (LF)\r- Carriage return (CR)\t- Tab\\- Backslash\"- Double quote\'- Single quote\0- Null character\xNN- Hexadecimal byte (e.g.,\x41for 'A')\u{NNNN}- Unicode code point (e.g.,\u{1F600}for 😀)
Boolean Literals
true
false
Array Literals
[1 2 3 4 5] // array of i32
[1.0 2.0 3.0] // array of f64
[[1 2] [3 4]] // 2D array