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/print.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 src/print.c (limited to 'src/print.c') diff --git a/src/print.c b/src/print.c new file mode 100644 index 0000000..e653571 --- /dev/null +++ b/src/print.c @@ -0,0 +1,50 @@ +#include "./include/print.h" +#include "./include/ast.h" +#include + +void print_string(ast_t *str) { printf("=> %s\n", str->string_value); } + +void print_int(ast_t *i) { printf("=> %d\n", i->int_value); } + +void print_bool(ast_t *b) { + if (b->bool_value) + printf("=> T\n"); + else + printf("=> F\n"); +} + +void print_float(ast_t *f) { printf("=> %f\n", f->float_value); } + +void print_symbol(ast_t *s) { printf("=> %s\n", s->string_value); } + +void print_func(ast_t *f) {} + +void print_pair(ast_t *p) {} +void print(ast_t *res) { + switch (res->type) { + case AST_STRING: + print_string(res); + break; + case AST_INT: + print_int(res); + break; + case AST_BOOL: + print_bool(res); + break; + case AST_FLOAT: + print_float(res); + break; + case AST_FUNCTION: + print_func(res); + break; + case AST_SYMBOL: + print_symbol(res); + break; + case AST_PAIR: + print_pair(res); + break; + case AST_ROOT: + printf("Yeah, let's not do that\n"); + break; + } +} -- cgit