From 6ab9c3732793b6fd40e6388cf1b08756194c0ea6 Mon Sep 17 00:00:00 2001 From: Quinn Stephens Date: Thu, 7 Nov 2024 16:59:19 -0500 Subject: [compiler] Parse return statements Laid groundwork for statements and AST trees. Currently return values are not supported, expression parsing must be implemented first. Also stopped dumping parsed type definitions. Signed-off-by: Quinn Stephens --- compiler/parser/proc.c | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) (limited to 'compiler/parser/proc.c') diff --git a/compiler/parser/proc.c b/compiler/parser/proc.c index bbbdad1..b32f5e9 100644 --- a/compiler/parser/proc.c +++ b/compiler/parser/proc.c @@ -7,6 +7,7 @@ #include #include "debug.h" #include "parser/proc.h" +#include "parser/stmt.h" #include "parser/type.h" #include "parser.h" @@ -119,26 +120,29 @@ parse_proc(struct parser *ctx) } } - /* Add procedure to parser's registry */ - hashmap_add(ctx->procs, &proc->hashmap_entry); - /* We are finished now if this is just a declaration */ if (ctx->tok.kind == TK_SEMICOLON) { + proc->node = NULL; + + /* Add procedure to parser's registry */ + hashmap_add(ctx->procs, &proc->hashmap_entry); + next_token(ctx); return; } if (ctx->tok.kind != TK_LBRACE) { + proc->node = NULL; tok_error(&ctx->tok, "Expected \";\" or \"{\"\n"); return; } - /* TODO: Parse body/code */ + /* Allocate AST root node for body */ + proc->node = ast_new_node(NK_PROCEDURE); - if (next_token(ctx)->kind != TK_RBRACE) { - tok_error(&ctx->tok, "Expected \"}\" after procedure body\n"); - return; - } + /* Parse procedure body (code) */ + parse_stmt_block(ctx, proc->node, proc); - next_token(ctx); + /* Add procedure to parser's registry */ + hashmap_add(ctx->procs, &proc->hashmap_entry); } -- cgit v1.2.3