From b79902cd36b2c5b54bbf0f07078fc528754977b2 Mon Sep 17 00:00:00 2001 From: hachem Date: Sat, 19 Sep 2026 14:38:55 +0200 Subject: feat: variables and shi --- ast.h | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'ast.h') diff --git a/ast.h b/ast.h index 39924b6..d17eaef 100644 --- a/ast.h +++ b/ast.h @@ -1,5 +1,11 @@ #pragma once +#include +#include + +// 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); -- cgit v1.3