diff options
author | Carlos Maniero <carlos@maniero.me> | 2023-05-09 16:18:18 -0300 |
---|---|---|
committer | Johnny Richard <johnny@johnnyrichard.com> | 2023-05-09 22:54:46 +0200 |
commit | ad54ee1182b1549880eddc8b1969d3992d9f7f1d (patch) | |
tree | 34d6a33a6a5ccba3ff6198d0e49f1e1d4701fc27 /src/ast_pretty_printer.c | |
parent | 8c8fc8cc30b38ef00d606a4991b655df97a52fb6 (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_pretty_printer.c')
-rw-r--r-- | src/ast_pretty_printer.c | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/src/ast_pretty_printer.c b/src/ast_pretty_printer.c index 718d22a..e2d007a 100644 --- a/src/ast_pretty_printer.c +++ b/src/ast_pretty_printer.c @@ -63,6 +63,31 @@ ast_pretty_printer_print_ast(ast_pretty_printer_t *printer, ast_node_t *ast) assert(ast); switch (ast->kind) { + case AST_IF_STMT: { + ast_if_stmt_t if_stmt = ast->data.if_stmt; + ast_pretty_printer_printf(printer, "IfStmt\n"); + ast_pretty_printer_add_indentation(printer); + { + ast_pretty_printer_printf(printer, "condition:\n"); + ast_pretty_printer_add_indentation(printer); + { + ast_pretty_printer_set_lst_children(printer); + ast_pretty_printer_print_ast(printer, if_stmt.condition); + + ast_pretty_printer_rm_indentation(printer); + } + ast_pretty_printer_printf(printer, "body:\n"); + ast_pretty_printer_add_indentation(printer); + { + ast_pretty_printer_set_lst_children(printer); + ast_pretty_printer_print_ast(printer, if_stmt.body); + + ast_pretty_printer_rm_indentation(printer); + } + ast_pretty_printer_rm_indentation(printer); + } + break; + } case AST_BINARY_OPERATION: { ast_binary_operation_t binop = ast->data.binary_operation; ast_pretty_printer_printf(printer, "BinaryOperation operation='%c'\n", operation_kinds[binop.kind]); |