Primitive Types and Values
Grammar
literal ::= intnumber | floatnumber | "true" | "false"
int_type ::= "i8" | "i16" | "i32" | "i64" | "u8" | "u16" | "u32" | "u64"
float_type ::= "f16" | "f32" | "f64"
intnumber ::= (decimal | hexadecimal | binary) [int_type]
decimal ::= decdigit (decdigit |"_")*
hexadecimal ::= 0 ("x" | "X") hexdigit (hexdigit |"_")*
binary ::= 0 ("b" | "B") bindigit (bindigit | "_")*
floatnumber ::= (pointfloat | exponentfloat) [float_type]
pointfloat ::= [intpart] fraction
exponentfloat ::= (intpart | pointfloat) exponent
intpart ::= decdigit (decdigit |"_")*
fraction ::= "." decdigit (decdigit |"_")*
exponent ::= ("e" | "E") ["+" | "-"] decdigit+
decdigit ::= "0"..."9"
hexdigit ::= decdigit | "a"..."f" | "A"..."F"
bindigit ::= "0" | "1"
Description
Boolean literals are written true and false. The primitive types in Wyn are:
- Signed integer types:
i8,i16,i32,i64 - Unsigned integer types:
u8,u16,u32,u64 - Floating-point types:
f16,f32,f64 - Boolean type:
bool
Numeric Literals
Numeric literals can be suffixed with their intended type. For example 42i8 is of type i8, and 1337e2f64 is of type f64. If no suffix is given, the type of the literal will be inferred based on its use. If the use is not constrained, integral literals will be assigned type i32, and decimal literals type f64.
Integer formats:
- Decimal:
42,1000,42i8 - Hexadecimal:
0xFF,0x1A2B(prefixed with0x) - Binary:
0b1010,0b11110000(prefixed with0b)
Float formats:
- Decimal:
3.14,1.5e-10,2.0f32
Underscores may be used as digit separators in numeric literals for readability (e.g., 1_000_000, 0xFF_FF_FF).