From 7dcbac1a3ce1c6fd87d79a0b76cdb20c8f090184 Mon Sep 17 00:00:00 2001 From: ubq323 Date: Thu, 3 Aug 2023 21:08:03 +0100 Subject: add strings to parser --- ast.c | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) (limited to 'ast.c') diff --git a/ast.c b/ast.c index 2443283..d0a7ffe 100644 --- a/ast.c +++ b/ast.c @@ -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]; } -- cgit v1.2.3