Rewrote grammar, implemented two visitors
This commit is contained in:
@@ -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
|
||||
;
|
||||
|
||||
Reference in New Issue
Block a user