summaryrefslogtreecommitdiff
path: root/ast.c
diff options
context:
space:
mode:
authorubq323 <ubq323@ubq323.website>2023-07-11 00:36:32 +0100
committerubq323 <ubq323@ubq323.website>2023-07-11 00:36:32 +0100
commit1e19e4c6e052909bf76a30b26f63dcf32576e994 (patch)
tree3632bd275f0735636aec5a8b9cf5f85796719b8a /ast.c
parent86c9a7e5c47c5c3eb70e06ea5e278de8022fd5b2 (diff)
parsing sexprs
Diffstat (limited to 'ast.c')
-rw-r--r--ast.c32
1 files changed, 30 insertions, 2 deletions
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;
+ }
+
+}