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.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'ast.c') diff --git a/ast.c b/ast.c index e420ba3..ed694f9 100644 --- a/ast.c +++ b/ast.c @@ -5,6 +5,22 @@ #include #include +void name_init(struct Name* name) +{ + name->length = 0; + name->text[0] = '\0'; +} + +bool name_push(struct Name* name, char character) +{ + if (name->length == NAME_LENGTH_MAX) + return false; + + name->text[name->length++] = character; + name->text[name->length] = '\0'; + return true; +} + static struct Node* node_new(enum NodeKind kind) { struct Node* node = calloc(1, sizeof *node); @@ -55,6 +71,14 @@ struct Node* node_ternary(enum NodeKind kind, struct Node* first, struct Node* s return node; } +struct Node* node_named(enum NodeKind kind, const struct Name* name, struct Node* first) +{ + struct Node* node = node_new(kind); + (void)snprintf(node->name, sizeof node->name, "%s", name->text); + node->first = first; + return node; +} + struct Node* node_append(struct Node* list, struct Node* node) { struct Node* last = list; -- cgit v1.3