diff options
author | Preston Pan <preston@nullring.xyz> | 2023-01-03 09:45:40 -0800 |
---|---|---|
committer | Preston Pan <preston@nullring.xyz> | 2023-01-03 09:45:40 -0800 |
commit | b2c539fadfa7ea3eea2e5f7c0c37b5f5f1370c5a (patch) | |
tree | 0f4b9db8c6bf345c9011667c9fbb61393d93a347 /src/include | |
parent | 9f342255a2260480701cc2ac2d0c623d4aba1348 (diff) |
actually evaluates and prints something now!
Diffstat (limited to 'src/include')
-rw-r--r-- | src/include/.visitor.h.swp (renamed from src/include/.ast.h.swp) | bin | 12288 -> 12288 bytes | |||
-rw-r--r-- | src/include/ast.h | 9 | ||||
-rw-r--r-- | src/include/parser.h | 2 | ||||
-rw-r--r-- | src/include/print.h | 6 | ||||
-rw-r--r-- | src/include/visitor.h | 2 |
5 files changed, 16 insertions, 3 deletions
diff --git a/src/include/.ast.h.swp b/src/include/.visitor.h.swp Binary files differindex 31e16ab..febe477 100644 --- a/src/include/.ast.h.swp +++ b/src/include/.visitor.h.swp 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); |