Rewrote grammar, implemented two visitors

This commit is contained in:
Marvin Kaiser
2019-10-29 09:51:43 +01:00
parent ea248733d0
commit 64c41122d0
11 changed files with 539 additions and 103 deletions

View File

@@ -1,25 +1,44 @@
grammar Klang;
parse
: multiplicativeExpr <EOF>
: block <EOF>
;
multiplicativeExpr
: unaryExpression (MULT unaryExpression)*
block
: statement*
;
unaryExpression
: INTEGER_LITERAL
statement
: print
;
print
: PRINT expression SCOL
;
expression
: atom MULT atom #multiplicationExpression
| atom op=(ADD | SUB) atom #additiveExpression
| atom MOD atom #moduloExpression
| SUB atom #unaryNegateExpression
;
atom
: INTEGER_LITERAL #intAtom
;
PRINT: 'print';
SCOL: ';';
MULT: '*';
ADD: '+';
SUB: '-';
MOD: '%';
INTEGER_LITERAL
: [0-9]+
;
MULT
: '*'
;
WS
: [ \t\r\n] -> skip
;