summaryrefslogtreecommitdiff
path: root/src/eval.c
diff options
context:
space:
mode:
authorKai Stevenson <kai@kaistevenson.com>2023-03-03 23:51:26 -0800
committerKai Stevenson <kai@kaistevenson.com>2023-03-03 23:51:26 -0800
commit2b06f74c5a95e95d3c98137c9498cc3bc51e1968 (patch)
tree4febbc0fe916b4f9f1f4980c235d6f47ab2b5e56 /src/eval.c
parent4f9c20f5701372f72ec016762737a74f793bb127 (diff)
added parser error handling with line numbers, print function prints all arguments
Diffstat (limited to 'src/eval.c')
-rw-r--r--src/eval.c27
1 files changed, 15 insertions, 12 deletions
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 {