From ad54ee1182b1549880eddc8b1969d3992d9f7f1d Mon Sep 17 00:00:00 2001 From: Carlos Maniero Date: Tue, 9 May 2023 16:18:18 -0300 Subject: parser: parses an if statement no code generation This commit parses a if statement following the grammar bellow: if boolean_expression { n_epressions; } No else neither code generation was implemented. Signed-off-by: Carlos Maniero --- src/ast.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'src/ast.c') diff --git a/src/ast.c b/src/ast.c index 1200e30..5790c05 100644 --- a/src/ast.c +++ b/src/ast.c @@ -47,6 +47,10 @@ ast_node_destroy(ast_node_t *node) case AST_FUNCTION_DECLARATION: ast_node_destroy(node->data.function.body); break; + case AST_IF_STMT: + ast_node_destroy(node->data.if_stmt.condition); + ast_node_destroy(node->data.if_stmt.body); + break; case AST_BLOCK: ast_node_destroy_vector(node->data.block.body); break; @@ -139,6 +143,25 @@ ast_node_new_literal_integer(uint32_t number) return node; } +ast_node_t * +ast_node_new_if_stmt(ast_node_t *condition, ast_node_t *body) +{ + ast_node_t *node = ast_node_new(); + + *node = (ast_node_t){ + .kind = AST_IF_STMT, + .result_type = TYPE_VOID, + .data = { + .if_stmt = { + .condition = condition, + .body = body + }, + }, + }; + + return node; +} + ast_node_t * ast_node_new_literal_bool(bool boolean) { -- cgit v1.2.3