/* ================================================================================ | | | The Artichoke Programming Language | | Official EBNF Grammar | | | ================================================================================ */ /* --- Program Structure --- */ /* A program is a sequence of top-level declarations and statements. */ = * = "export" | = | | | non_exportable_declaration = | | | | | = "module" "{" ( | | | | )* "}" = "import" ";" = ( "::" "*" )? = "using" "=" ";" /* --- Declarations --- */ /* Rules for defining functions, structs, enums, and their components. */ = "fn" ? "(" ? ")" ( "->" )? = "this" ("," ( "," )* )? | ( "," )* = ":" = "struct" ? "{" "}" = ( "," )* = ":" = "enum" ? "{" "}" = ( "," )* = ( "(" ")" )? = "<" ">" = ( "," )* = "typename" /* --- Statements & Control Flow --- */ /* Rules for code blocks, variable declarations, and control structures. */ = "{" * "}" = ";" | | ";" | ";" | ";" | ";" | ";" | | | | ";" = = ":" ( "=" )? | "=" = "let" | "def" = "if" "(" ")" ? ? = "else" = | ? = "|" "|" = ( ":=")? ( | | | | ) = "for" "(" ( | )? ";" ";" ? ")" = "for" "(" ":=" ")" = "while" "(" ")" ? ? = "do" "while" "(" ")" = "loop" = "match" "(" ")" "{" * ? "}" = "switch" "(" ")" "{" * ? "}" = ( "(" ")" )? "->" = "->" = "_" "->" = "break" ? = "continue" ? = "defer" ( | ) = "errdefer" ( | ) = "return" ? /* --- Expressions & Operator Precedence --- */ /* The full expression hierarchy, from lowest to highest precedence. */ = ( ( | ) )? = ( ( "||" | "or" ) )* = ( ( "&&" | "and" ) )* = ( )? = ( )* = ( )* = ( )* = ( )* = * = ( | )* /* --- Primary Expressions & Literals --- */ /* The highest-precedence expressions, including literals and grouped expressions. */ = | | ( "{" "}" )? = ( "<" ">" )? = | | | | = "(" ")" = "(" ")" = ( ",")* ? = ( | )? ","? = ( "," )* = ":" = ( "," )* = "null" = "true" | "false" = /* Assumed to be defined by the tokenizer */ = /* Assumed to be defined by the tokenizer */ = /* Assumed to be defined by the tokenizer */ /* --- Operators --- */ /* Definitions for all operator token sets. */ = "=" = "+=" | "-=" | "*=" | "/=" | "%=" | "&=" | "|=" | "<<=" | ">>=" | "||=" | "&&=" = "==" | "!=" | ">" | "<" | ">=" | "<=" = "&" | "^" | "|" = "<<" | ">>" = "+" | "-" = "*" | "/" | "%" = "!" | "-" | "~" | "&" | "*" = "[" | "." | "::" ( "<" ">" )? | "->" | ".@" ? | ".[" "]" | ".#" | ".*" = | ":" ? "]" = "]" | ":" ? "]" /* --- Type System --- */ /* Rules for defining types, type names, and type qualifiers. */ = ? = ( "*" | "[]" ) ? | "$" ? | "?" ? = ( "*" | "[]" ) ? | "$" ? = ( "*" | "[]" ) ? | "?" ? = ( "::" ( "<" ">" )? )* = ( "::" identifier )* = ( "," )* /* --- Lexical Tokens & Base Definitions --- */ /* The lowest-level building blocks of the language. */ = = | | = "_" | [a-z] | [A-Z] = | = "0" = [1-9] = E /* Represents an empty terminal string */ = /* End Of File */