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/include/.ast.h.swp | Bin 12288 -> 0 bytes src/include/.visitor.h.swp | Bin 0 -> 12288 bytes src/include/ast.h | 9 ++++++++- src/include/parser.h | 2 +- src/include/print.h | 6 ++++++ src/include/visitor.h | 2 +- 6 files changed, 16 insertions(+), 3 deletions(-) delete mode 100644 src/include/.ast.h.swp create mode 100644 src/include/.visitor.h.swp (limited to 'src/include') diff --git a/src/include/.ast.h.swp b/src/include/.ast.h.swp deleted file mode 100644 index 31e16ab..0000000 Binary files a/src/include/.ast.h.swp and /dev/null differ diff --git a/src/include/.visitor.h.swp b/src/include/.visitor.h.swp new file mode 100644 index 0000000..febe477 Binary files /dev/null and b/src/include/.visitor.h.swp differ diff --git a/src/include/ast.h b/src/include/ast.h index ca07c9d..a5095e1 100644 --- a/src/include/ast.h +++ b/src/include/ast.h @@ -4,6 +4,8 @@ typedef struct AST_STRUCT { enum { + /* root node */ + AST_ROOT, /* complex types */ AST_PAIR, AST_SYMBOL, @@ -14,9 +16,12 @@ typedef struct AST_STRUCT { AST_FLOAT, AST_FUNCTION, } type; + /* we need to know the amount of expressions in the root node */ + int root_size; + struct AST_STRUCT **subnodes; /* For functions, the car will be a list of variables, and the cdr will be the - * expression */ + * expression. */ int argument_number; /* number of arguments that function accepts. Used for speeding up stuff. */ struct AST_STRUCT *car; @@ -43,4 +48,6 @@ ast_t *init_ast_bool(bool value); ast_t *init_ast_symbol(char *value); ast_t *init_ast_function(ast_t *car, ast_t *cdr); + +ast_t *init_ast_root(ast_t **subnodes, int size); #endif diff --git a/src/include/parser.h b/src/include/parser.h index 64ae792..7b26696 100644 --- a/src/include/parser.h +++ b/src/include/parser.h @@ -44,5 +44,5 @@ void parse_bind(parser_t *parser); ast_t *parse_expr(parser_t *parser); -ast_t *read_in(char *s); +ast_t *parse_all(parser_t *parser); #endif diff --git a/src/include/print.h b/src/include/print.h index 9dbecbd..866f63e 100644 --- a/src/include/print.h +++ b/src/include/print.h @@ -12,5 +12,11 @@ void print_float(ast_t *f); void print_func(ast_t *f); +void print_list(ast_t *f); + +void print_symbol(ast_t *s); + +void print_pair(ast_t *p); + void print(ast_t *res); #endif diff --git a/src/include/visitor.h b/src/include/visitor.h index 87f2853..6af052b 100644 --- a/src/include/visitor.h +++ b/src/include/visitor.h @@ -10,7 +10,7 @@ typedef struct { ast_t *root; } visitor_t; -void eval_error(visitor_t *v); +void eval_error(visitor_t *v, ast_t *e); visitor_t *init_visitor(ast_t *root); -- cgit