Complete Grammar
This page collects the complete grammar of the language in one place. Every production below is defined canonically on the page indicated; those pages remain authoritative, and this page is a duplicate reference. The lexical productions are defined on the lexical structure page.
Lexical Helper Productions
See lexical structure.
letter = "A" | "B" | "C" | "D" | "E" | "F" | "G"
| "H" | "I" | "J" | "K" | "L" | "M" | "N"
| "O" | "P" | "Q" | "R" | "S" | "T" | "U"
| "V" | "W" | "X" | "Y" | "Z"
| "a" | "b" | "c" | "d" | "e" | "f" | "g"
| "h" | "i" | "j" | "k" | "l" | "m" | "n"
| "o" | "p" | "q" | "r" | "s" | "t" | "u"
| "v" | "w" | "x" | "y" | "z" ;
digit = "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" ;
hex_digit = digit | "A" | "B" | "C" | "D" | "E" | "F"
| "a" | "b" | "c" | "d" | "e" | "f" ;
character = ? any ASCII source character ? ;
quotation_mark = '"' ;
apostrophe = "'" ;
reverse_solidus = "\" ;
escape_sequence = reverse_solidus, ( "n" | "r" | "t" | reverse_solidus | quotation_mark
| "x", hex_digit, hex_digit ) ;
char_escape_sequence = reverse_solidus, ( "n" | "r" | "t" | reverse_solidus | apostrophe
| "x", hex_digit, hex_digit ) ;
string_character = character - ( quotation_mark | reverse_solidus | ? line feed ? | ? carriage return ? ) ;
char_character = character - ( apostrophe | reverse_solidus | ? line feed ? | ? carriage return ? ) ;
exponent_part = "e", [ "-" ], digit, { [ "_" ], digit } ;
Lexical Token Productions
See lexical structure.
identifier = ( letter | "_" ), { letter | digit | "_" } ;
(* Literals *)
integer_literal = digit, { [ "_" ], digit }
| "0x", hex_digit, { [ "_" ], hex_digit } ;
float_literal = digit, { [ "_" ], digit }, ".", digit, { [ "_" ], digit }, [ exponent_part ] ;
boolean_literal = true | false ;
string_literal = quotation_mark, { string_character | escape_sequence }, quotation_mark ;
char_literal = apostrophe, ( char_character | char_escape_sequence ), apostrophe ;
(* Reserved Keywords *)
alloc = "alloc" ;
collect = "collect" ;
i8 = "i8" ;
i16 = "i16" ;
i32 = "i32" ;
i64 = "i64" ;
u8 = "u8" ;
u16 = "u16" ;
u32 = "u32" ;
u64 = "u64" ;
f32 = "f32" ;
f64 = "f64" ;
bool = "bool" ;
function = "function" ;
enum = "enum" ;
namespace = "namespace" ;
over = "over" ;
structure = "structure" ;
define = "define" ;
let = "let" ;
match = "match" ;
false = "false" ;
true = "true" ;
type = "type" ;
(* Symbols *)
ampersand = "&" ;
ampersand_ampersand = "&&" ;
bang = "!" ;
bang_equal = "!=" ;
colon = ":" ;
colon_colon = "::" ;
comma = "," ;
dot = "." ;
equal = "=" ;
equal_equal = "==" ;
greater_than = ">" ;
greater_than_equal = ">=" ;
left_brace = "{" ;
left_bracket = "[" ;
left_paren = "(" ;
less_than = "<" ;
less_than_equal = "<=" ;
minus = "-" ;
number_sign = "#" ;
percent = "%" ;
plus = "+" ;
question_mark = "?" ;
right_brace = "}" ;
right_bracket = "]" ;
right_paren = ")" ;
semicolon = ";" ;
solidus = "/" ;
star = "*" ;
vertical_bar_vertical_bar = "||" ;
Type Grammar
See types and the pages defining each type expression form: type, namespace, boolean, numeric, function, tuple, structure, and enumeration. A tuple type is a tuple expression, the names of structure and enumeration declarations are symbol references, and handle and slice types are formed by the & and [] unary prefixes in the expression grammar.
type_type = type ;
namespace_type = namespace ;
boolean_type = bool ;
numeric_type = i8 | i16 | i32 | i64
| u8 | u16 | u32 | u64
| f32 | f64 ;
function_type = function, left_paren, [ expression, { comma, expression } ], right_paren, colon, expression ;
Global Declaration Grammar
See global declarations and the pages defining each declaration kind (functions, structures, enumerations, namespaces, defines).
program = { global_declaration } ;
global_declaration = function_declaration | structure_declaration | enumeration_declaration | namespace_declaration | define_declaration ;
function_declaration_parameter = identifier, colon, expression ;
function_declaration_parameter_list = left_paren, [ function_declaration_parameter, { comma, function_declaration_parameter } ], right_paren ;
function_declaration = function, identifier, function_declaration_parameter_list, colon, expression, expression ;
structure_declaration_field = identifier, colon, expression, semicolon ;
structure_declaration = structure, identifier, left_brace, { structure_declaration_field }, right_brace ;
enumeration_declaration_variant = identifier, [ colon, expression ], semicolon ;
enumeration_declaration = enum, identifier, left_brace, { enumeration_declaration_variant }, right_brace ;
namespace_declaration = namespace, identifier, left_brace, { global_declaration }, right_brace ;
define_declaration = define, identifier, equal, expression ;
Expression Grammar
The operators are defined on the arithmetic, comparison, and logical pages, the prefix forms on the negation, logical not, length, handle, and slice pages, the primary forms on the primary expressions page and the pages linked there, and the postfix operations on their pages (call, static access, dynamic access, subscript, subslice, construction).
expression = conditional_expression ;
conditional_expression = logical_or_expression, [ question_mark, conditional_expression, colon, conditional_expression ] ;
logical_or_expression = logical_and_expression, { logical_disjunction_operator, logical_and_expression } ;
logical_and_expression = comparison_expression, { logical_conjunction_operator, comparison_expression } ;
comparison_expression = additive_expression, { comparison_operator, additive_expression } ;
additive_expression = multiplicative_expression, { additive_operator, multiplicative_expression } ;
multiplicative_expression = unary_expression, { multiplicative_operator, unary_expression } ;
unary_expression = { unary_operator | ampersand | left_bracket, right_bracket }, postfix_expression ;
unary_operator = negation_operator | logical_not_operator | length_operator ;
negation_operator = minus ;
logical_not_operator = bang ;
length_operator = number_sign ;
postfix_expression = primary_expression, { postfix_operation } ;
postfix_operation = call_operation | static_access_operation | dynamic_access_operation | subscript_operation | subslice_operation | construction_operation ;
call_operation = left_paren, [ expression, { comma, expression } ], right_paren ;
static_access_operation = colon_colon, identifier ;
dynamic_access_operation = dot, identifier ;
subscript_operation = left_bracket, expression, right_bracket ;
subslice_operation = left_bracket, expression, comma, expression, right_bracket ;
construction_operation = left_brace, [ expression, { comma, expression } ], right_brace ;
primary_expression = integer_literal | float_literal | boolean_literal | string_literal | char_literal | symbol_reference | parenthesized_expression | tuple_expression | numeric_type | boolean_type | namespace_type | type_type | function_type | match_expression | scope_expression | alloc_expression | collect_expression ;
parenthesized_expression = left_paren, expression, right_paren ;
tuple_expression = left_paren, expression, comma, expression, { comma, expression }, right_paren ;
symbol_reference = identifier ;
match_pattern = symbol_reference, { static_access_operation } ;
match_arm = match_pattern, colon, expression, semicolon ;
match_expression = match, left_paren, expression, right_paren, left_brace, { match_arm }, right_brace ;
let_binding = let, identifier, equal, expression, semicolon ;
scope_expression = left_brace, { let_binding }, expression, right_brace ;
alloc_expression = alloc_handle_expression | alloc_slice_expression ;
alloc_handle_expression = alloc, unary_expression ;
alloc_slice_expression = alloc, left_bracket, expression, right_bracket, unary_expression ;
collect_expression = collect, unary_expression, over, unary_expression ;
additive_operator = plus | minus ;
multiplicative_operator = star | solidus | percent ;
comparison_operator = equal_equal | bang_equal | less_than | less_than_equal
| greater_than | greater_than_equal ;
logical_conjunction_operator = ampersand_ampersand ;
logical_disjunction_operator = vertical_bar_vertical_bar ;