From 967be9e750221ab2ab783f95df79bb26d290a45e Mon Sep 17 00:00:00 2001 From: Martial Simon Date: Mon, 15 Sep 2025 01:07:58 +0200 Subject: add: added projects --- 21sh/ll-expr/src/ast/ast.h | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 21sh/ll-expr/src/ast/ast.h (limited to '21sh/ll-expr/src/ast/ast.h') 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 + +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 */ -- cgit v1.2.3