/* * AST (Abstract Syntax Tree) definitions. * Copyright (c) 2023-2024, Quinn Stephens and the OSMORA team. * Provided under the BSD 3-Clause license. */ #ifndef _PARSER_AST_H #define _PARSER_AST_H #include #include "list.h" enum ast_node_kind { NK_UNKNOWN, NK_PROCEDURE, NK_RETURN }; struct ast_node { struct list_entry list_entry; enum ast_node_kind kind; struct ast_node *parent; struct list children; }; static inline void ast_append_child(struct ast_node *parent, struct ast_node *child) { child->parent = parent; list_append(&parent->children, &child->list_entry); } static inline void ast_remove_child(struct ast_node *child) { list_remove(&child->list_entry); child->parent->children.length--; } static inline struct ast_node * ast_new_node(enum ast_node_kind kind) { struct ast_node *node; node = malloc(sizeof(struct ast_node)); node->kind = kind; node->parent = NULL; list_init(&node->children); return node; } #endif /* !_PARSER_AST_H */