summary refs log tree commit diff
path: root/grammar
diff options
context:
space:
mode:
authorErik Oosting2023-12-11 15:25:24 +0100
committerErik Oosting2023-12-11 15:25:24 +0100
commit0e96e69659c7c31927b7eee5c40d017b035a6471 (patch)
tree8d037de425102e8ba6ebf0921aa7f58bacab1976 /grammar
Initial commit
Adding grammar
Diffstat (limited to 'grammar')
-rw-r--r--grammar/ANF.g428
1 files changed, 28 insertions, 0 deletions
diff --git a/grammar/ANF.g4 b/grammar/ANF.g4
new file mode 100644
index 0000000..95ab835
--- /dev/null
+++ b/grammar/ANF.g4
@@ -0,0 +1,28 @@
+grammar ANF;
+
+aexp
+    : IDENT
+    | NUMBER
+    | aexp '+' aexp
+    | aexp '-' aexp
+    | aexp '*' aexp
+    | aexp '/' aexp
+    | '(' IDENT ':' cexp ')'
+    ;
+
+funcall
+    : IDENT '(' aexp (',' aexp)* ')'
+    | aexp
+    ;
+cexp
+    : 'let' IDENT '=' funcall 'in' cexp
+    | funcall
+    ;
+
+IDENT: Letter (Letter | Digit)*;
+NUMBER: Digit+;
+
+fragment Letter: 'A' .. 'Z' | 'a' .. 'z';
+fragment Digit: '0'..'9';
+
+WS: [ \t\n\r]+ -> skip;