implement variable assignment

This commit is contained in:
2019-11-18 18:54:24 +01:00
parent b38369b7a5
commit 2af9f369cf
6 changed files with 53 additions and 3 deletions

View File

@@ -5,7 +5,7 @@ parse
;
program
: functionDef* expression
: functionDef* expression SCOL
;
functionDef
@@ -23,6 +23,7 @@ braced_block
statement
: print
| if_statement
| variable_assignment
;
print
@@ -33,6 +34,10 @@ if_statement
: IF OPAR cond = expression CPAR then = braced_block (ELSE (alt = braced_block | elif = if_statement) )?
;
variable_assignment
: IDENT EQUAL expression SCOL
;
expression
: atom MULT atom #multiplicationExpression
| atom op=(ADD | SUB) atom #additiveExpression
@@ -43,7 +48,7 @@ expression
;
functionCall
: IDENT OPAR arguments CPAR SCOL
: IDENT OPAR arguments CPAR
;
arguments
@@ -66,6 +71,7 @@ CBRK: '}';
OPAR: '(';
CPAR: ')';
COMMA: ',';
EQUAL: '=';
MULT: '*';
ADD: '+';