From 6fe77e2f20f045b89ed10c3952f8f088e9bd3d6c Mon Sep 17 00:00:00 2001 From: Preston Pan Date: Wed, 4 Jan 2023 18:22:24 -0800 Subject: fully functional parser (collisions might be a problem) --- src/parser.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'src/parser.c') diff --git a/src/parser.c b/src/parser.c index 62e1c5f..16be8e1 100644 --- a/src/parser.c +++ b/src/parser.c @@ -127,15 +127,18 @@ ast_t *parse_function(parser_t *parser) { void parse_bind(parser_t *parser) { parser_move(parser); - parser_eat(parser, TOKEN_ID); - + if (parser->tokens[parser->i]->type != TOKEN_ID) + parser_error(parser); token_t *t = parser->tokens[parser->i]; char *name = t->value; parser_move(parser); ast_t *expr = parse_expr(parser); /* unevaluated expr will be evaluated when hash table transfers to visitor JIT */ - hash_table_add(parser->symbol_table, name, expr); + + parser_move(parser); + /* if (parser->tokens[parser->i]->type != TOKEN_RPAREN) */ + /* parser_error(parser); */ } ast_t *parse_list(parser_t *parser) { @@ -201,8 +204,11 @@ ast_t *parse_expr(parser_t *parser) { return parse_symbol(parser); else if (t->type == TOKEN_LPAREN) return parse_list(parser); - else + else { + printf("DEBUG\n"); + printf("%d", t->type); parser_error(parser); + } return NULL; } -- cgit