summaryrefslogtreecommitdiff
path: root/src/ast.c
diff options
context:
space:
mode:
authorCarlos Maniero <carlos@maniero.me>2023-05-09 16:18:18 -0300
committerJohnny Richard <johnny@johnnyrichard.com>2023-05-09 22:54:46 +0200
commitad54ee1182b1549880eddc8b1969d3992d9f7f1d (patch)
tree34d6a33a6a5ccba3ff6198d0e49f1e1d4701fc27 /src/ast.c
parent8c8fc8cc30b38ef00d606a4991b655df97a52fb6 (diff)
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 <carlos@maniero.me>
Diffstat (limited to 'src/ast.c')
-rw-r--r--src/ast.c23
1 files changed, 23 insertions, 0 deletions
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;
@@ -140,6 +144,25 @@ ast_node_new_literal_integer(uint32_t number)
}
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)
{
ast_node_t *node = ast_node_new();