addition: proccessing of prefix op

This commit is contained in:
2026-05-12 18:33:52 -06:00
parent 59f99059bb
commit e30b3d7175
2 changed files with 12 additions and 1 deletions

View File

@@ -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);

View File

@@ -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);