diff options
Diffstat (limited to 'parser.c')
| -rw-r--r-- | parser.c | 17 |
1 files changed, 13 insertions, 4 deletions
@@ -324,6 +324,9 @@ static void parse_group(struct group_node* p_node) { static void parse_if(struct if_node* p_node) { expect_kw("if"); + scope_push(&scope); + p_node->scope = scope; + expect(TK_LPAREN); p_node->cond = protected_alloc(sizeof(struct expr_node)); parse_expr(p_node->cond); @@ -333,11 +336,14 @@ static void parse_if(struct if_node* p_node) { parse_stmt(p_node->true_branch); peek_or_panic(); - if (tok.type != TK_IDENT || strcmp(tok.data.ident, "else") != 0) return; - expect_kw("else"); + if (tok.type == TK_IDENT && strcmp(tok.data.ident, "else") == 0) { + expect_kw("else"); - p_node->false_branch = protected_alloc(sizeof(struct stmt_node)); - parse_stmt(p_node->false_branch); + p_node->false_branch = protected_alloc(sizeof(struct stmt_node)); + parse_stmt(p_node->false_branch); + } + + scope_pop(&scope); } static void parse_stmt_assign(struct stmt_node* p_node) { @@ -419,6 +425,9 @@ static void parse_args_decl(struct args_decl_node** pp_decl) { } static void parse_fn_decl(struct fn_decl_node* p_node) { + if (scope->next_out != NULL) + PARSER_PANIC("functions can only be define in the root scope"); + parse_type_ref(&p_node->return_type); expect(TK_IDENT); |
