diff options
author | Preston Pan <preston@nullring.xyz> | 2023-01-03 13:52:38 -0800 |
---|---|---|
committer | Preston Pan <preston@nullring.xyz> | 2023-01-03 13:52:38 -0800 |
commit | 41bfa91100b3ddf36496b5dff6e10bfd5394017d (patch) | |
tree | 23695ac010a36de78825c09c7fb0c17cf0d8a723 /src/parser.c | |
parent | 3c35be76e515098431643155b66e61a1c64816ae (diff) |
implemented parse_all; I think i fixed some bugs but i forgor
Diffstat (limited to 'src/parser.c')
-rw-r--r-- | src/parser.c | 20 |
1 files changed, 17 insertions, 3 deletions
diff --git a/src/parser.c b/src/parser.c index 1fff876..92e9ccf 100644 --- a/src/parser.c +++ b/src/parser.c @@ -25,11 +25,11 @@ parser_t *init_parser(lexer_t *lexer) { while (true) { t = lexer_collect_next(lexer); - if (t == NULL) - break; size++; p->tokens = realloc(p->tokens, size * sizeof(token_t *)); p->tokens[size - 1] = t; + if (t == NULL) + break; } p->size = size; @@ -205,5 +205,19 @@ ast_t *parse_expr(parser_t *parser) { return NULL; } -ast_t *parse_all(parser_t *parser) {} +ast_t *parse_all(parser_t *parser) { + token_t *t = parser->tokens[parser->i]; + ast_t **asts = malloc(sizeof(ast_t *)); + ast_t *cur; + int i = 0; + while (t != NULL) { + cur = parse_expr(parser); + i++; + asts = realloc(asts, i * sizeof(ast_t *)); + asts[i - 1] = cur; + t = parser->tokens[parser->i]; + } + return init_ast_root(asts, i); +} + void parser_error(parser_t *parser) { exit(1); } |