#include "all.h" #include #include static const char *type_name(ast_type_e type) { switch (type) { case AST_INC: return "INC"; case AST_DEC: return "DEC"; case AST_PTR_INC: return "PTR_INC"; case AST_PTR_DEC: return "PTR_DEC"; case AST_OUT: return "OUT"; case AST_IN: return "IN"; case AST_LOOP: return "LOOP"; case AST_CLEAR: return "CLEAR"; default: return "?"; } } void ast_dump(ast_node_t *node, int depth) { while (node) { for (int i = 0; i < depth; i++) fprintf(stderr, " "); fprintf(stderr, "%s(%dx / %zu len)", type_name(node->type), node->val, node->children.len); switch (node->type) { case AST_INC: case AST_DEC: case AST_PTR_INC: case AST_PTR_DEC: break; default: break; } fprintf(stderr, "\n"); if (node->type == AST_LOOP) { for (int i = 0; i < depth; i++) fprintf(stderr, " "); fprintf(stderr, "{\n"); for (int i = 0; i < node->children.len; i++) ast_dump(node->children._data[i], depth + 1); for (size_t i = 0; i < depth; i++) fprintf(stderr, " "); fprintf(stderr, "}\n"); } node = node->next; } }