summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPreston Pan <preston@nullring.xyz>2023-01-03 13:52:38 -0800
committerPreston Pan <preston@nullring.xyz>2023-01-03 13:52:38 -0800
commit41bfa91100b3ddf36496b5dff6e10bfd5394017d (patch)
tree23695ac010a36de78825c09c7fb0c17cf0d8a723 /src
parent3c35be76e515098431643155b66e61a1c64816ae (diff)
implemented parse_all; I think i fixed some bugs but i forgor
Diffstat (limited to 'src')
-rw-r--r--src/include/.ast.h.swpbin12288 -> 12288 bytes
-rw-r--r--src/parser.c20
2 files changed, 17 insertions, 3 deletions
diff --git a/src/include/.ast.h.swp b/src/include/.ast.h.swp
index c3e8ba3..355bb9f 100644
--- a/src/include/.ast.h.swp
+++ b/src/include/.ast.h.swp
Binary files differ
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); }