hachem.wtf
aboutsummaryrefslogtreecommitdiff
path: root/ast.c
diff options
context:
space:
mode:
authorhachem <im@hachem.wtf>2026-09-19 14:38:55 +0200
committerhachem <im@hachem.wtf>2026-09-19 14:38:55 +0200
commitb79902cd36b2c5b54bbf0f07078fc528754977b2 (patch)
tree0f3baa55b58831c46c7631619f76eef5cb371f71 /ast.c
parent7160bdb390ef1c9bdcfb0c075b33be39d62860f3 (diff)
feat: variables and shi
Diffstat (limited to 'ast.c')
-rw-r--r--ast.c24
1 files changed, 24 insertions, 0 deletions
diff --git a/ast.c b/ast.c
index e420ba3..ed694f9 100644
--- a/ast.c
+++ b/ast.c
@@ -5,6 +5,22 @@
#include <stdlib.h>
#include <string.h>
+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;