diff options
Diffstat (limited to 'ast.c')
-rw-r--r-- | ast.c | 21 |
1 files changed, 14 insertions, 7 deletions
@@ -57,6 +57,15 @@ AstNode astnode_new_symbol(char *s) { }; } +AstNode astnode_new_string(char *s) { + return (AstNode){ + .ty =AST_STRING, + .as = { + .str = s + } + }; +} + void astnode_disp(AstNode *a) { switch (a->ty) { case AST_NUM: @@ -70,20 +79,18 @@ void astnode_disp(AstNode *a) { } printf(")"); break; - case AST_SYMBOL:; + case AST_SYMBOL: + case AST_STRING: printf("%s:%s ",ast_ty_to_str(a->ty), a->as.str); break; + } } const char* ty_names[] = { - "list", "num", "symbol" + "list", "num", "symbol", "string" }; const char *ast_ty_to_str(AstTy ty) { - if (ty >= AST_TY_LAST || ty < 0) { - return "???"; - } else { - return ty_names[ty]; - } + return ty_names[ty]; } |