summaryrefslogtreecommitdiff
path: root/include/parser/ast.h
diff options
context:
space:
mode:
authorQuinn Stephens <quinn@osmora.org>2024-11-07 16:59:19 -0500
committerQuinn Stephens <quinn@osmora.org>2024-11-07 16:59:19 -0500
commit6ab9c3732793b6fd40e6388cf1b08756194c0ea6 (patch)
treee7ae86e1bad944192f0b6fd130cb7d84afa4f180 /include/parser/ast.h
parent063c40584ae78a396b558a5e2a08e3d871450c0b (diff)
[compiler] Parse return statementsmain
Laid groundwork for statements and AST trees. Currently return values are not supported, expression parsing must be implemented first. Also stopped dumping parsed type definitions. Signed-off-by: Quinn Stephens <quinn@osmora.org>
Diffstat (limited to 'include/parser/ast.h')
-rw-r--r--include/parser/ast.h38
1 files changed, 37 insertions, 1 deletions
diff --git a/include/parser/ast.h b/include/parser/ast.h
index 03be1bd..9463511 100644
--- a/include/parser/ast.h
+++ b/include/parser/ast.h
@@ -7,14 +7,50 @@
#ifndef _PARSER_AST_H
#define _PARSER_AST_H
+#include <stdlib.h>
+#include "list.h"
+
enum ast_node_kind {
NK_UNKNOWN,
- NK_
+ 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 */