From f05c9eddc9f4dff41016b5363925e59c2de671e2 Mon Sep 17 00:00:00 2001 From: Thomas Voss Date: Tue, 2 Jul 2024 00:34:12 +0200 Subject: Completely rework how types are handled --- grammar.ebnf | 75 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 grammar.ebnf (limited to 'grammar.ebnf') diff --git a/grammar.ebnf b/grammar.ebnf new file mode 100644 index 0000000..a5f5e50 --- /dev/null +++ b/grammar.ebnf @@ -0,0 +1,75 @@ +(* vi: ft=ebnf + *) + +program + : {'pub' declaration} + ; + +declaration + : mutdecl + | constdecl + ; + +assignment + : expression '=' expression ';' + ; + +mutdecl + : IDENT ':' type ';' + | IDENT ':' [type] '=' (expression | ellipsis) ';' + ; + +constdecl + : IDENT ':' [type] ':' (expression ';' | function) + ; + +function + : prototype '{' statement* '}' + ; + +prototype + : '(' ')' [type] + ; + +statement + | declaration + | assignment + | 'return' [expression] ';' + ; + +expression + : IDENT + | NUMERIC + | unop expression + | expression binop expression + | '(' expression ')' + ; + +unop + : '-' + | '&' + | '+' + | '~' + ; + +binop + : '+' + | '%' + | '&' + | '*' + | '-' + | '/' + | '<<' + | '>>' + | '|' + | '~' + ; + +type + : IDENT + ; + +ellipsis + : '…' + | '...' + ; -- cgit v1.2.3