Added if statement

This commit is contained in:
Marvin Kaiser
2019-10-29 10:30:18 +01:00
parent 64c41122d0
commit d43fa90bc3
9 changed files with 343 additions and 96 deletions

View File

@@ -8,27 +8,47 @@ block
: statement*
;
braced_block
: OBRK statement* CBRK
;
statement
: print
| if_statement
;
print
: PRINT expression SCOL
;
if_statement
: IF expression THEN braced_block (ELSE braced_block)?
;
expression
: atom MULT atom #multiplicationExpression
| atom op=(ADD | SUB) atom #additiveExpression
| atom MOD atom #moduloExpression
| SUB atom #unaryNegateExpression
| atom #atomExpression
;
atom
: INTEGER_LITERAL #intAtom
;
/*
if 5 = 5 then whatever else whatever
*/
PRINT: 'print';
IF: 'if';
THEN: 'then';
ELSE: 'else';
SCOL: ';';
OBRK: '{';
CBRK: '}';
MULT: '*';
ADD: '+';