From e3761429de464c42cc2798dc858bf6b43883d9dc Mon Sep 17 00:00:00 2001 From: Johnny Richard Date: Tue, 18 Apr 2023 07:13:55 +0200 Subject: 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 --- src/parser.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) (limited to 'src/parser.c') 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 #include +#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) + ); } -- cgit v1.2.3