summaryrefslogtreecommitdiff
path: root/ast.c
diff options
context:
space:
mode:
authorubq323 <ubq323@ubq323.website>2023-07-12 02:22:10 +0100
committerubq323 <ubq323@ubq323.website>2023-07-12 02:22:10 +0100
commitf9f7b92fdda17efe2dca455d6f641a424a97b2db (patch)
tree03f8bfa66a7b944fe9f908972b6ab2dde8b5297f /ast.c
parentd9eb793ad606fd47d17a17af24b78b46f2180f84 (diff)
more code
Diffstat (limited to 'ast.c')
-rw-r--r--ast.c18
1 files changed, 15 insertions, 3 deletions
diff --git a/ast.c b/ast.c
index ee2f0ab..2443283 100644
--- a/ast.c
+++ b/ast.c
@@ -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];
+ }
+}
+