From 2b06f74c5a95e95d3c98137c9498cc3bc51e1968 Mon Sep 17 00:00:00 2001 From: Kai Stevenson Date: Fri, 3 Mar 2023 23:51:26 -0800 Subject: added parser error handling with line numbers, print function prints all arguments --- src/eval.c | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) (limited to 'src/eval.c') diff --git a/src/eval.c b/src/eval.c index a99ad4d..8ffe965 100644 --- a/src/eval.c +++ b/src/eval.c @@ -256,19 +256,22 @@ sym_t* try_eval_internal(sym_t* symbol, hashtable_t* symbolScope) { } } else if (hash == get_hash("print")) { - sym_t* v = eval(symbol->args[0], symbolScope); - if (v->litType == INT) { - printf("%d\n", symtoi(v)); - } - else if (v->litType == FLOAT) { - printf("%.5f\n", symtof(v)); - } - else if (v->litType == STRING) { - char* s = symtos(v); - printf("%s\n", s); - free(s); + for (int i = 0; i < symbol->argCount; i++) { + sym_t* v = eval(symbol->args[i], symbolScope); + if (v->litType == INT) { + printf("%d", symtoi(v)); + } + else if (v->litType == FLOAT) { + printf("%.5f", symtof(v)); + } + else if (v->litType == STRING) { + char* s = symtos(v); + printf("%s", s); + free(s); + } + destroy_sym(v); } - destroy_sym(v); + printf("\n"); return init_sym_int(1); } else { -- cgit v1.3.1