diff options
Diffstat (limited to 'ast.c')
-rw-r--r-- | ast.c | 18 |
1 files changed, 14 insertions, 4 deletions
@@ -27,7 +27,7 @@ void astvec_append(AstVec *v, AstNode val) { void astnode_append(AstNode *l, AstNode val) { // printf(" astnode_append: %d\n",l->ty); - assert(l->ty == AST_LIST); + assert(l->ty == AST_LIST || l->ty == AST_ARR); astvec_append(&l->as.list, val); } @@ -48,6 +48,14 @@ AstNode astnode_new_list() { } }; } +AstNode astnode_new_arr() { + return (AstNode){ + .ty = AST_ARR, + .as = { + .list = astvec_new() + } + }; +} AstNode astnode_new_ident(const char *s) { return (AstNode){ @@ -74,7 +82,8 @@ void astnode_free(AstNode *a) { case AST_STRING: free(a->as.str); break; - case AST_LIST:; + case AST_LIST: + case AST_ARR:; AstVec *v = &a->as.list; for (int i = 0; i < v->len; i++) { astnode_free(&v->vals[i]); @@ -92,7 +101,8 @@ void astnode_disp(AstNode *a) { case AST_NUM: printf("%s:%d ",ast_ty_to_str(a->ty),a->as.num); break; - case AST_LIST:; + case AST_LIST: + case AST_ARR:; AstVec *v = &a->as.list; printf("%s:(",ast_ty_to_str(a->ty)); for (int i = 0; i < v->len; i++) { @@ -109,7 +119,7 @@ void astnode_disp(AstNode *a) { } const char* ty_names[] = { - "list", "num", "ident", "string" + "list", "num", "ident", "string", "arr", }; const char *ast_ty_to_str(AstTy ty) { return ty_names[ty]; |