summaryrefslogtreecommitdiff
path: root/ast.c
diff options
context:
space:
mode:
authorubq323 <ubq323@ubq323.website>2023-08-03 21:08:03 +0100
committerubq323 <ubq323@ubq323.website>2023-08-03 21:09:26 +0100
commit7dcbac1a3ce1c6fd87d79a0b76cdb20c8f090184 (patch)
tree199dc390df6fd0604a11e1ffc6671c5995bddcb7 /ast.c
parent62126fd5070a88488fe8375105863f500b43fb7c (diff)
add strings to parser
Diffstat (limited to 'ast.c')
-rw-r--r--ast.c21
1 files changed, 14 insertions, 7 deletions
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];
}