From e30b3d7175dfbda028e377e553a789165fd80c1b Mon Sep 17 00:00:00 2001 From: laentropia Date: Tue, 12 May 2026 18:33:52 -0600 Subject: [PATCH] addition: proccessing of prefix op --- include/parser.h | 2 +- src/parser.c | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/include/parser.h b/include/parser.h index 0c8f080..75bc70c 100644 --- a/include/parser.h +++ b/include/parser.h @@ -32,8 +32,8 @@ typedef struct { ASTNode *nud(ArraySlice *slice); ASTNode *led(ArraySlice *slice, size_t right_precedence); -uint8_t prefix_lbp(ASTNode node); uint8_t prefix_rbp(ASTNode node); +uint8_t postfix_lbp(ASTNode node); uint8_t infix_lbp(ASTNode node); uint8_t infix_rbp(ASTNode node); diff --git a/src/parser.c b/src/parser.c index fc4c142..2d956f5 100644 --- a/src/parser.c +++ b/src/parser.c @@ -87,6 +87,17 @@ ASTNode *parse_expr(ArraySlice *slice, Arena *arena, uint8_t min_bp) { ) ); + // if is unary then take prefix bp and continue + // to the right, no need to allocate left side + // because we just did and right side + // WILL return a valid allocated pointer. + if (left_side->type == NODE_UNARY_OP) { + uint8_t rbp = prefix_rbp(*left_side); + ASTNode *righ_side = parse_expr(slice, arena, rbp); + + left_side->data.unary.val = righ_side; + return left_side; + } // Should check if is Integer or number arrayslice_next(slice, left_side);