diff options
| author | hachem <im@hachem.wtf> | 2026-09-19 14:38:55 +0200 |
|---|---|---|
| committer | hachem <im@hachem.wtf> | 2026-09-19 14:38:55 +0200 |
| commit | b79902cd36b2c5b54bbf0f07078fc528754977b2 (patch) | |
| tree | 0f3baa55b58831c46c7631619f76eef5cb371f71 /ast.h | |
| parent | 7160bdb390ef1c9bdcfb0c075b33be39d62860f3 (diff) | |
feat: variables and shi
Diffstat (limited to 'ast.h')
| -rw-r--r-- | ast.h | 19 |
1 files changed, 19 insertions, 0 deletions
@@ -1,5 +1,11 @@ #pragma once +#include <stdbool.h> +#include <stddef.h> + +// names longer than this are refused, nobody needs a longer name +#define NAME_LENGTH_MAX 15 + enum NodeKind { NODE_CHAR, @@ -19,32 +25,45 @@ enum NodeKind VALUE_TUPLE_SIZE, VALUE_INTEGRAL_CONSTANT, VALUE_CONDITIONAL, + VALUE_VARIABLE, COND_TRUE, COND_FALSE, COND_IS_SAME, COND_EQUAL, COND_LESS, + STMT_DECLARE, STMT_EMIT, STMT_STATIC_ASSERT }; +struct Name +{ + char text[NAME_LENGTH_MAX + 1]; + size_t length; +}; + struct Node { enum NodeKind kind; int line; char character; + char name[NAME_LENGTH_MAX + 1]; struct Node* first; struct Node* second; struct Node* third; struct Node* next; }; +void name_init(struct Name* name); +bool name_push(struct Name* name, char character); + struct Node* node_leaf(enum NodeKind kind); struct Node* node_char(char character); struct Node* node_unary(enum NodeKind kind, struct Node* first); struct Node* node_binary(enum NodeKind kind, struct Node* first, struct Node* second); struct Node* node_ternary(enum NodeKind kind, struct Node* first, struct Node* second, struct Node* third); +struct Node* node_named(enum NodeKind kind, const struct Name* name, struct Node* first); struct Node* node_append(struct Node* list, struct Node* node); void node_free(struct Node* node); |
