summaryrefslogtreecommitdiff
path: root/21sh/ll-expr/src/ast/ast.h
diff options
context:
space:
mode:
Diffstat (limited to '21sh/ll-expr/src/ast/ast.h')
-rw-r--r--21sh/ll-expr/src/ast/ast.h40
1 files changed, 40 insertions, 0 deletions
diff --git a/21sh/ll-expr/src/ast/ast.h b/21sh/ll-expr/src/ast/ast.h
new file mode 100644
index 0000000..01e0064
--- /dev/null
+++ b/21sh/ll-expr/src/ast/ast.h
@@ -0,0 +1,40 @@
+#ifndef AST_H
+#define AST_H
+
+#include <unistd.h>
+
+enum ast_type
+{
+ AST_PLUS,
+ AST_MINUS,
+ AST_MUL,
+ AST_DIV,
+ AST_NUMBER,
+ AST_NEG
+};
+
+/**
+ * This very simple AST structure should be sufficient for a simple AST.
+ * It is however, NOT GOOD ENOUGH for more complicated projects, such as a
+ * shell. Please read the project guide for some insights about other kinds of
+ * ASTs.
+ */
+struct ast
+{
+ enum ast_type type; // The kind of node we're dealing with
+ ssize_t value; // If the node is a number, it stores its value
+ struct ast *left; // The left branch if any, unary or binary
+ struct ast *right; // The right branch of the binary node
+};
+
+/**
+ ** \brief Allocates a new ast with the given type.
+ */
+struct ast *ast_new(enum ast_type type);
+
+/**
+ ** \brief Recursively frees the given ast.
+ */
+void ast_free(struct ast *ast);
+
+#endif /* !AST_H */