diff options
author | Himbeer <himbeer@disroot.org> | 2024-10-02 15:37:37 +0200 |
---|---|---|
committer | Himbeer <himbeer@disroot.org> | 2024-10-02 15:37:37 +0200 |
commit | 6dcaccdab64366d086898dc289fda9d80b98e636 (patch) | |
tree | 8da5292fc36b745885d10d715296ba101d54b750 | |
parent | 7c2cfd1657924a9d66757a627eef9caa117684a9 (diff) |
Implement optional return expressions
This is the implementation of commit
7c2cfd1657924a9d66757a627eef9caa117684a9.
-rw-r--r-- | include/parse.h | 2 | ||||
-rw-r--r-- | src/parse.c | 6 |
2 files changed, 5 insertions, 3 deletions
diff --git a/include/parse.h b/include/parse.h index 21584cc..b3e8eee 100644 --- a/include/parse.h +++ b/include/parse.h @@ -25,7 +25,7 @@ struct ast_block { }; struct ast_return { - struct ast_expr value; + struct ast_expr *value; }; struct ast_declaration { diff --git a/src/parse.c b/src/parse.c index 511cb18..3fa1498 100644 --- a/src/parse.c +++ b/src/parse.c @@ -1097,8 +1097,10 @@ parse_return(struct lexer *lexer, struct ast_return *out) return false; } - if (!parse_expr(lexer, &out->value)) { - error(lex_loc(lexer), "syntax error: expected expression"); + out->value = must_malloc(sizeof(struct ast_expr)); + if (!parse_expr(lexer, out->value)) { + free(out->value); + out->value = NULL; } return true; |