diff options
Diffstat (limited to 'ast.c')
| -rw-r--r-- | ast.c | 24 |
1 files changed, 24 insertions, 0 deletions
@@ -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; |
