diff options
author | ubq323 <ubq323@ubq323.website> | 2023-08-03 21:08:03 +0100 |
---|---|---|
committer | ubq323 <ubq323@ubq323.website> | 2023-08-03 21:09:26 +0100 |
commit | 7dcbac1a3ce1c6fd87d79a0b76cdb20c8f090184 (patch) | |
tree | 199dc390df6fd0604a11e1ffc6671c5995bddcb7 /ast.c | |
parent | 62126fd5070a88488fe8375105863f500b43fb7c (diff) |
add strings to parser
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]; } |