From d3d052117a40e2b8df7ee04b65c39ffe6886b722 Mon Sep 17 00:00:00 2001 From: momoyon Date: Thu, 24 Apr 2025 16:49:03 +0500 Subject: [PATCH] [main.c] Return NULL on binary parsing if failed to parse primary. --- main.c | 4 ++++ main.momo | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/main.c b/main.c index 75ff8c1..5405cc4 100644 --- a/main.c +++ b/main.c @@ -758,6 +758,7 @@ Expression *factor(Arena *arena, Parser *p) { while (parser_match(p, TK_DIVIDE) || parser_match(p, TK_MULTIPLY)) { Token op = parser_previous(p); Expression *rhs = unary(arena, p); + if (rhs == NULL) return rhs; Expression *new_expr = (Expression *)arena_alloc(arena, sizeof(Expression)); new_expr->kind = EXPR_BINARY; @@ -781,6 +782,7 @@ Expression *term(Arena *arena, Parser *p) { Token operator = parser_previous(p); Expression *rhs = factor(arena, p); + if (rhs == NULL) return NULL; Expression *new_expr = (Expression *)arena_alloc(arena, sizeof(Expression)); new_expr->kind = EXPR_BINARY; @@ -805,6 +807,7 @@ Expression *comparision(Arena *arena, Parser *p) { Token operator = parser_previous(p); Expression *rhs = term(arena, p); + if (rhs == NULL) return NULL; Expression *new_expr = (Expression *)arena_alloc(arena, sizeof(Expression)); new_expr->kind = EXPR_BINARY; @@ -828,6 +831,7 @@ Expression *equality(Arena *arena, Parser *p) { Token operator = parser_previous(p); Expression *rhs = comparision(arena, p); + if (rhs == NULL) return NULL; Expression *new_expr = (Expression *)arena_alloc(arena, sizeof(Expression)); new_expr->kind = EXPR_BINARY; diff --git a/main.momo b/main.momo index 9f9370e..9a849bb 100644 --- a/main.momo +++ b/main.momo @@ -1 +1 @@ -1 + (4 / ); +1 + (1 0); -- 2.39.5