diff options
author | Johnny Richard <johnny@johnnyrichard.com> | 2023-04-18 07:13:55 +0200 |
---|---|---|
committer | Carlos Maniero <carlosmaniero@gmail.com> | 2023-04-18 09:54:50 -0300 |
commit | e3761429de464c42cc2798dc858bf6b43883d9dc (patch) | |
tree | 7a0d37205db4aadc6fc079c5474cb3d36fd25328 /src/parser.c | |
parent | bf2bbaf31487a3935f1a27dc51886d6f53c3d73d (diff) |
ast: Create AST visitor to traverse the tree
In the future we want to have the possibility of traverse the tree and
pretty print it or generate binary for other platform like LLVM or
transpile to C.
This solution also implements the gas assembly x86_64 Linux code
generation by using the visitor interface.
Signed-off-by: Johnny Richard <johnny@johnnyrichard.com>
Diffstat (limited to 'src/parser.c')
-rw-r--r-- | src/parser.c | 15 |
1 files changed, 7 insertions, 8 deletions
diff --git a/src/parser.c b/src/parser.c index 593f75a..b956c4e 100644 --- a/src/parser.c +++ b/src/parser.c @@ -20,6 +20,7 @@ #include <stdlib.h> #include <string.h> +#include "ast.h" #include "lexer.h" #include "parser.h" @@ -92,9 +93,7 @@ parser_parse_return_stmt(parser_t *parser) char number_as_str[number_token.value.size]; string_view_to_str(&number_token.value, number_as_str); - return (ast_return_stmt_t) { - .number = atoi(number_as_str) - }; + return ast_return_stmt_create(atoi(number_as_str)); } ast_function_t @@ -106,9 +105,9 @@ parser_parse_function(parser_t *parser) expected_token(parser, TOKEN_COLON); type_t return_type = parser_parse_type(parser); - return (ast_function_t) { - .name = func_name_token.value, - .return_type = return_type, - .body = parser_parse_return_stmt(parser) - }; + return ast_function_create( + func_name_token.value, + return_type, + parser_parse_return_stmt(parser) + ); } |