diff options
author | ubq323 <ubq323@ubq323.website> | 2023-07-12 02:22:10 +0100 |
---|---|---|
committer | ubq323 <ubq323@ubq323.website> | 2023-07-12 02:22:10 +0100 |
commit | f9f7b92fdda17efe2dca455d6f641a424a97b2db (patch) | |
tree | 03f8bfa66a7b944fe9f908972b6ab2dde8b5297f /ast.c | |
parent | d9eb793ad606fd47d17a17af24b78b46f2180f84 (diff) |
more code
Diffstat (limited to 'ast.c')
-rw-r--r-- | ast.c | 18 |
1 files changed, 15 insertions, 3 deletions
@@ -60,18 +60,30 @@ AstNode astnode_new_symbol(char *s) { void astnode_disp(AstNode *a) { switch (a->ty) { case AST_NUM: - printf("n:%d ",a->as.num); + printf("%s:%d ",ast_ty_to_str(a->ty),a->as.num); break; case AST_LIST:; AstVec *v = &a->as.list; - printf("l:("); + printf("%s:(",ast_ty_to_str(a->ty)); for (int i = 0; i < v->len; i++) { astnode_disp(&v->vals[i]); } printf(")"); break; case AST_SYMBOL:; - printf("s:%s ",a->as.str); + printf("%s:%s ",ast_ty_to_str(a->ty), a->as.str); break; } } + +const char* ty_names[] = { + "list", "num", "symbol" +}; +const char *ast_ty_to_str(AstTy ty) { + if (ty >= AST_TY_LAST || ty < 0) { + return "???"; + } else { + return ty_names[ty]; + } +} + |