From 8edafecb633fec2b6327d996c1e7c282f4f1792f Mon Sep 17 00:00:00 2001 From: Preston Pan Date: Sat, 7 Jan 2023 12:22:37 -0800 Subject: fixing print --- doc/main.nxs | 4 ++-- src/main.c | 2 +- src/visitor.c | 11 ++--------- 3 files changed, 5 insertions(+), 12 deletions(-) diff --git a/doc/main.nxs b/doc/main.nxs index 381161a..3dd0ebf 100644 --- a/doc/main.nxs +++ b/doc/main.nxs @@ -2,5 +2,5 @@ (bind factorial (lambda (n) (if (= n 0) 1 (* n (factorial (print(- n 1))))))) -(fib 7) -(+ (factorial 5) 10) +(print(fib 7)) +(print (+ (factorial 5) 10)) diff --git a/src/main.c b/src/main.c index 5315549..db5846d 100644 --- a/src/main.c +++ b/src/main.c @@ -164,7 +164,7 @@ int main(int argc, char **argv) { parser_t *parser = init_parser(lexer); visitor_t *visitor = init_visitor(parser); ast_t *root = eval(visitor); - print_root(root); + /* print_root(root); */ } return 0; diff --git a/src/visitor.c b/src/visitor.c index 22f09ed..374ad02 100644 --- a/src/visitor.c +++ b/src/visitor.c @@ -2,6 +2,7 @@ #include "./include/hash_table.h" #include "./include/macros.h" #include "./include/parser.h" +#include "./include/print.h" #include "./include/stack.h" #include #include @@ -445,15 +446,7 @@ ast_t *eval_list(visitor_t *v, ast_t *e) { eval_error(v, e); ast_t *arg1 = eval_expr(v, args->car); - if (arg1->type == AST_STRING) { - printf("%s\n", arg1->string_value); - } else if (arg1->type == AST_INT) { - printf("%d\n", arg1->int_value); - } else if (arg1->type == AST_FLOAT) { - printf("%f\n", arg1->float_value); - } else { - printf("print statement for this datatype not implemented.\n"); - } + print(arg1); return arg1; } -- cgit