summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
Diffstat (limited to 'include')
-rw-r--r--include/lexer/token.h1
-rw-r--r--include/list.h7
-rw-r--r--include/parser/ast.h38
-rw-r--r--include/parser/proc.h3
-rw-r--r--include/parser/stmt.h16
5 files changed, 64 insertions, 1 deletions
diff --git a/include/lexer/token.h b/include/lexer/token.h
index 2ba5408..cc04c95 100644
--- a/include/lexer/token.h
+++ b/include/lexer/token.h
@@ -25,6 +25,7 @@ typedef enum {
TK_TYPE,
TK_ENUM,
TK_STRUCT,
+ TK_RET,
/*
* Operators.
diff --git a/include/list.h b/include/list.h
index 0364f7c..69d0c33 100644
--- a/include/list.h
+++ b/include/list.h
@@ -7,6 +7,7 @@
#ifndef _LIST_H
#define _LIST_H
+#include <stdbool.h>
#include <stddef.h>
struct list_entry {
@@ -20,6 +21,12 @@ struct list {
size_t length;
};
+static inline bool
+list_is_empty(struct list *list)
+{
+ return list->head == (struct list_entry*)list;
+}
+
static inline void
list_remove(struct list_entry *entry)
{
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 */
diff --git a/include/parser/proc.h b/include/parser/proc.h
index 0cc8471..f74fee6 100644
--- a/include/parser/proc.h
+++ b/include/parser/proc.h
@@ -9,6 +9,7 @@
#include "list.h"
#include "hashmap.h"
+#include "parser/ast.h"
#include "parser/var.h"
struct parameter {
@@ -27,6 +28,8 @@ struct procedure {
struct type *ret_typ;
int ret_n_ptrs;
+
+ struct ast_node *node;
};
void parse_proc(struct parser *ctx);
diff --git a/include/parser/stmt.h b/include/parser/stmt.h
new file mode 100644
index 0000000..caf022c
--- /dev/null
+++ b/include/parser/stmt.h
@@ -0,0 +1,16 @@
+/*
+ * Statement parser.
+ * Copyright (c) 2023-2024, Quinn Stephens and the OSMORA team.
+ * Provided under the BSD 3-Clause license.
+ */
+
+#ifndef _PARSER_STMT_H
+#define _PARSER_STMT_H
+
+#include "parser/ast.h"
+#include "parser/proc.h"
+#include "parser.h"
+
+void parse_stmt_block(struct parser *ctx, struct ast_node *parent, struct procedure *proc);
+
+#endif /* !_PARSER_STMT_H */