From 9f342255a2260480701cc2ac2d0c623d4aba1348 Mon Sep 17 00:00:00 2001 From: Preston Pan Date: Tue, 3 Jan 2023 00:27:06 -0800 Subject: add some comments; fix some bugs in advance --- src/include/.ast.h.swp | Bin 0 -> 12288 bytes src/include/ast.h | 6 +++++- src/include/hash_table.h | 4 ++++ src/include/parser.h | 7 +++---- 4 files changed, 12 insertions(+), 5 deletions(-) create mode 100644 src/include/.ast.h.swp (limited to 'src/include') diff --git a/src/include/.ast.h.swp b/src/include/.ast.h.swp new file mode 100644 index 0000000..31e16ab Binary files /dev/null and b/src/include/.ast.h.swp differ diff --git a/src/include/ast.h b/src/include/ast.h index f7be3d5..ca07c9d 100644 --- a/src/include/ast.h +++ b/src/include/ast.h @@ -17,15 +17,19 @@ typedef struct AST_STRUCT { /* For functions, the car will be a list of variables, and the cdr will be the * expression */ + int argument_number; /* number of arguments that function accepts. Used for + speeding up stuff. */ struct AST_STRUCT *car; struct AST_STRUCT *cdr; - char *string_value; + char *string_value; /* Also is symbol value */ int int_value; double float_value; bool bool_value; } ast_t; +ast_t *init_ast(int type); + ast_t *init_ast_string(char *value); ast_t *init_ast_int(int value); diff --git a/src/include/hash_table.h b/src/include/hash_table.h index df2d368..833daee 100644 --- a/src/include/hash_table.h +++ b/src/include/hash_table.h @@ -32,6 +32,8 @@ void sl_list_add(sl_list_t *l, char *key, ast_t *value); ast_t *sl_list_get(sl_list_t *l, char *key); +bool sl_list_exists(sl_list_t *l, char *key); + void sl_list_free(sl_list_t *l); hash_table_t *init_hash_table(int size); @@ -40,6 +42,8 @@ void hash_table_add(hash_table_t *h, char *key, ast_t *value); ast_t *hash_table_get(hash_table_t *h, char *key); +bool hash_table_exists(hash_table_t *h, char *key); + unsigned long hash(char *key, int size); void hash_table_free(hash_table_t *h); diff --git a/src/include/parser.h b/src/include/parser.h index 97a7fd9..64ae792 100644 --- a/src/include/parser.h +++ b/src/include/parser.h @@ -13,6 +13,7 @@ typedef struct { int i; int size; bool finished; + bool is_global; } parser_t; parser_t *init_parser(lexer_t *lexer); @@ -21,7 +22,7 @@ void parser_error(parser_t *parser); void parser_move(parser_t *parser); -void parser_eat(parser_t *parser, token_t *token); +void parser_eat(parser_t *parser, int type); ast_t *parse_string(parser_t *parser); @@ -39,9 +40,7 @@ ast_t *parse_symbol(parser_t *parser); ast_t *parse_function(parser_t *parser); -ast_t *parse_list(parser_t *parser); - -ast_t *parse_bind(parser_t *parser); +void parse_bind(parser_t *parser); ast_t *parse_expr(parser_t *parser); -- cgit