From 1e19e4c6e052909bf76a30b26f63dcf32576e994 Mon Sep 17 00:00:00 2001 From: ubq323 Date: Tue, 11 Jul 2023 00:36:32 +0100 Subject: parsing sexprs --- ast.c | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) (limited to 'ast.c') diff --git a/ast.c b/ast.c index 94c0a66..7474d45 100644 --- a/ast.c +++ b/ast.c @@ -16,7 +16,7 @@ AstVec astvec_new() { void astvec_append(AstVec *v, AstNode val) { if (v->len == v->cap) { size_t newcap = v->cap * 2; - printf("%ld to %ld\n", v->cap, newcap); + // printf("%ld to %ld\n", v->cap, newcap); v->vals = realloc(v->vals, newcap * sizeof(AstNode)); v->cap = newcap; } @@ -25,7 +25,7 @@ void astvec_append(AstVec *v, AstNode val) { } void astnode_append(AstNode *l, AstNode val) { - printf(" astnode_append: %d\n",l->ty); + // printf(" astnode_append: %d\n",l->ty); assert(l->ty == AST_LIST); astvec_append(&l->as.list, val); } @@ -48,3 +48,31 @@ AstNode astnode_new_list() { }; } +AstNode astnode_new_symbol(char *s) { + return (AstNode){ + .ty =AST_SYMBOL, + .as = { + .str = s + } + }; +} + +void astnode_disp(AstNode *a) { + switch (a->ty) { + case AST_NUM: + printf("n:%d ",a->as.num); + break; + case AST_LIST:; + AstVec *v = &a->as.list; + printf("l:("); + for (int i = 0; i < v->len; i++) { + astnode_disp(&v->vals[i]); + } + printf(")"); + break; + case AST_SYMBOL:; + printf("s:%s ",a->as.str); + break; + } + +} -- cgit v1.2.3