FUCK YEAH, it works, it was the is_valid thing fo slices that was inverted, did the test by brute force and damn, is the expected AST
This commit is contained in:
32
src/parser.c
32
src/parser.c
@@ -74,7 +74,7 @@ ASTNode *parse_expr(ASTNodeSlice *slice, uint8_t min_bp) {
|
||||
*left_side = ASTNodeSlice_next(slice);
|
||||
|
||||
while (true) {
|
||||
if (ASTNodeSlice_is_valid(slice)) {
|
||||
if (!ASTNodeSlice_is_valid(slice)) {
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -102,35 +102,5 @@ ASTNode *parse_expr(ASTNodeSlice *slice, uint8_t min_bp) {
|
||||
return left_side;
|
||||
}
|
||||
|
||||
void print_AST(AST tree) {
|
||||
print_node(tree.head, 0);
|
||||
}
|
||||
|
||||
void print_node(ASTNode *node, int depth) {
|
||||
if (node == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (node->type == NODE_BINARY_OP) {
|
||||
print_node(node->data.binary.right, depth + 1);
|
||||
}
|
||||
|
||||
for (int i = 0; i < depth; i++) {
|
||||
printf(" ");
|
||||
}
|
||||
|
||||
switch (node->type) {
|
||||
case NODE_INTEGER:
|
||||
printf("%ld\n", node->data.integer);
|
||||
break;
|
||||
|
||||
case NODE_BINARY_OP:
|
||||
printf("%c\n", operator_to_char(node->data.binary.op));
|
||||
break;
|
||||
}
|
||||
|
||||
if (node->type == NODE_BINARY_OP) {
|
||||
print_node(node->data.binary.left, depth + 1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user