From a559125a2d7af771784614b7a2092cc7fb707345 Mon Sep 17 00:00:00 2001 From: ubq323 Date: Wed, 26 Jun 2024 22:45:16 +0100 Subject: array literals --- ast.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) (limited to 'ast.c') diff --git a/ast.c b/ast.c index b6fcbcf..4fbd471 100644 --- a/ast.c +++ b/ast.c @@ -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]; -- cgit v1.2.3