From b2c539fadfa7ea3eea2e5f7c0c37b5f5f1370c5a Mon Sep 17 00:00:00 2001 From: Preston Pan Date: Tue, 3 Jan 2023 09:45:40 -0800 Subject: actually evaluates and prints something now! --- src/visitor.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'src/visitor.c') diff --git a/src/visitor.c b/src/visitor.c index 25296c1..98a7d92 100644 --- a/src/visitor.c +++ b/src/visitor.c @@ -2,7 +2,9 @@ #include "./include/hash_table.h" #include "./include/macros.h" #include "./include/stack.h" +#include #include +#include visitor_t *init_visitor(ast_t *root) { visitor_t *v = (visitor_t *)malloc(sizeof(visitor_t)); @@ -23,3 +25,25 @@ bool is_self_evaluating(ast_t *e) { return true; return false; } + +/* Special symbols: car, cdr, quote, *, /, +, -, %, inc, dec, >, <, >=, <=, /=, + * =, equal (for strings), input */ +ast_t *eval_symbol(visitor_t *v, ast_t *e) {} + +ast_t *eval_list(visitor_t *v, ast_t *e) {} + +ast_t *eval_expr(visitor_t *v, ast_t *e) { + if (is_self_evaluating(e)) + return e; + else if (e->type == AST_PAIR) + return eval_list(v, e); + else if (e->type == AST_SYMBOL) + return eval_symbol(v, e); + else { + eval_error(v, e); + } +} + +ast_t *eval(visitor_t *v) {} + +void eval_error(visitor_t *v, ast_t *e) { exit(1); } -- cgit