aboutsummaryrefslogtreecommitdiff
path: root/grammar.ebnf
diff options
context:
space:
mode:
authorThomas Voss <mail@thomasvoss.com> 2024-07-02 00:34:12 +0200
committerThomas Voss <mail@thomasvoss.com> 2024-07-02 00:34:12 +0200
commitf05c9eddc9f4dff41016b5363925e59c2de671e2 (patch)
treef5c9bcaf2ed1def2f5f63b45192b093ae7413637 /grammar.ebnf
parent82c4e29648e972de9eb0836cf3e9f89fc8cee7d8 (diff)
Completely rework how types are handled
Diffstat (limited to 'grammar.ebnf')
-rw-r--r--grammar.ebnf75
1 files changed, 75 insertions, 0 deletions
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
+ : '…'
+ | '...'
+ ;