From 0e96e69659c7c31927b7eee5c40d017b035a6471 Mon Sep 17 00:00:00 2001 From: Erik Oosting Date: Mon, 11 Dec 2023 15:25:24 +0100 Subject: Initial commit Adding grammar --- grammar/ANF.g4 | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 grammar/ANF.g4 (limited to 'grammar/ANF.g4') 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; -- cgit 1.4.1-2-gfad0