DAMN, i still don't get it, i really don't want to ask some AI to do it but damn, i'm finding it REALLY difficult, is like the 4th article i read, i hope this is the one and that i can get going for fucks sake

This commit is contained in:
2026-03-24 21:04:36 -06:00
parent 27787308f2
commit acd5e9781e
2 changed files with 31 additions and 15 deletions

View File

@@ -9,9 +9,13 @@ typedef struct {
size_t pos;
} ASTNodeSlice;
ASTNode *nud(ASTNodeSlice *slice, size_t pos);
ASTNode *led(ASTNodeSlice *slice, size_t pos, size_t right_precedence);
ASTNode ASTNodeSlice_peek(ASTNodeSlice slice);
ASTNode ASTNodeSlice_next(ASTNodeSlice slice);
ASTNode *nud(ASTNodeSlice *slice);
ASTNode *led(ASTNodeSlice *slice, size_t right_precedence);
size_t node_lbp(ASTNode node);
size_t node_rbp(ASTNode node);
AST parse(ASTNodeArray arr);
AST parse_expr(ASTNodeSlice *arr);

View File

@@ -2,8 +2,30 @@
#include "lexer.h"
#include <stdlib.h>
size_t node_lbp(Operator op) {
switch (op) {
size_t node_lbp(ASTNode node) {
if (node.type == NODE_INTEGER) {
return 0;
}
switch (node.data.binary.op) {
case OP_ADD:
case OP_SUB:
return 10;
break;
case OP_DIV:
case OP_MUL:
return 20;
default:
return 0;
}
}
size_t node_rbp(ASTNode node) {
if (node.type == NODE_INTEGER) {
return 0;
}
switch (node.data.binary.op) {
case OP_ADD:
case OP_SUB:
return 10;
@@ -14,14 +36,4 @@ size_t node_lbp(Operator op) {
}
}
size_t node_rbp(Operator op) {
switch (op) {
case OP_ADD:
case OP_SUB:
return 10;
break;
case OP_DIV:
case OP_MUL:
return 20;
}
}