aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--example/example.imp5
-rw-r--r--src/interpreter.c2
-rw-r--r--src/parser.y4
3 files changed, 8 insertions, 3 deletions
diff --git a/example/example.imp b/example/example.imp
index d87c891..e1ddf22 100644
--- a/example/example.imp
+++ b/example/example.imp
@@ -1 +1,4 @@
-(x := 1; while x < 10 do x := (x * 2) end)
+x := 1;
+while x < 10 do
+ x := (x * 2)
+end \ No newline at end of file
diff --git a/src/interpreter.c b/src/interpreter.c
index 4449847..6b1ebe1 100644
--- a/src/interpreter.c
+++ b/src/interpreter.c
@@ -101,7 +101,7 @@ void exec_stmt(hashmap_t context, ASTNode *node) {
int old_val = context_get(context, name);
int new_val = eval_aexpr(context, node->u.d_let.aexp);
context_set(context, name, new_val);
- exec_stmt(context, node->u.d_let.stm);
+ exec_stmt(context, node->u.d_let.stm);
context_set(context, name, old_val);
return;
}
diff --git a/src/parser.y b/src/parser.y
index cb3544e..c1e1d0e 100644
--- a/src/parser.y
+++ b/src/parser.y
@@ -27,7 +27,7 @@ void yyerror(const char *s) {
%token <num> TOKEN_NUMERAL
%token TOKEN_ASSIGN
%token TOKEN_LEFT_PARENTHESIS TOKEN_RIGHT_PARENTHESIS
-%token TOKEN_SEMICOLON
+%left TOKEN_SEMICOLON
%token TOKEN_SKIP
%token TOKEN_IF TOKEN_THEN TOKEN_ELSE TOKEN_END TOKEN_WHILE TOKEN_DO TOKEN_VAR TOKEN_IN
%token TOKEN_PLUS TOKEN_MINUS TOKEN_MULTIPLY
@@ -50,6 +50,8 @@ statement : TOKEN_SKIP
{ $$ = ast_assign($1, $3); }
| TOKEN_LEFT_PARENTHESIS statement TOKEN_SEMICOLON statement TOKEN_RIGHT_PARENTHESIS
{ $$ = ast_seq($2, $4); }
+ | statement TOKEN_SEMICOLON statement
+ { $$ = ast_seq($1, $3); }
| TOKEN_IF boolean_expression TOKEN_THEN statement TOKEN_ELSE statement TOKEN_END
{ $$ = ast_if($2, $4, $6); }
| TOKEN_WHILE boolean_expression TOKEN_DO statement TOKEN_END