From a26684a417729699e95b335a3d00798237ffba9b Mon Sep 17 00:00:00 2001 From: Galin Simeonov Date: Fri, 4 Jun 2021 16:42:52 +0300 Subject: added the if statement --- src/backend/targets/print/print.c | 27 ++++++++++++++++++++++++--- src/backend/targets/print/print.h | 1 + 2 files changed, 25 insertions(+), 3 deletions(-) (limited to 'src/backend/targets/print') diff --git a/src/backend/targets/print/print.c b/src/backend/targets/print/print.c index 7649b91..3c33438 100644 --- a/src/backend/targets/print/print.c +++ b/src/backend/targets/print/print.c @@ -81,6 +81,12 @@ void print_keyword_enum(enum Keyword code) case KW_NOT: printf("KW_NOT"); break; + case KW_IF: + printf("KW_IF"); + break; + case KW_ELSE: + printf("KW_ELSE"); + break; default: printf("LEXERROR"); } @@ -158,6 +164,9 @@ void print_ast_enum(enum AST_Type type) case AST_TYPE_UNFINISHED_STATE: printf("AST_TYPE_UNFINISHED_STATE"); break; + case AST_TYPE_IF: + printf("AST_TYPE_IF"); + break; default: printf("AST_NOP"); } @@ -210,6 +219,9 @@ void print_ast(struct AST *tree) case AST_TYPE_UNFINISHED_STATE: print_ast_unchecked_state((struct AST_Unchecked_State*)tree); break; + case AST_TYPE_IF: + print_ast_if_statement((struct AST_If_Statement*)tree); + break; default: printf("noast"); } @@ -262,16 +274,16 @@ void print_ast_transition(struct AST_Transition* tree) assert(tree); printf("TRANSITION [\nFROM"); - print_ast(tree->from); + print_ast_state(tree->from); printf(" TO "); print_ast_state(tree->to); printf(" COMMAND {"); - if(tree->pipeline==NULL) + if(tree->statement==NULL) { printf("NULL"); }else { - print_ast_pipeline(tree->pipeline); + print_ast(tree->statement); } } @@ -381,4 +393,13 @@ void print_ast_unchecked_state(struct AST_Unchecked_State *tree) { print_token(tree->name); } +void print_ast_if_statement(struct AST_If_Statement *tree) +{ + printf("if <"); + print_ast(tree->condition); + printf(">\n"); + print_ast(tree->body); + if(tree->else_statement) + print_ast(tree->else_statement); +} #endif diff --git a/src/backend/targets/print/print.h b/src/backend/targets/print/print.h index d318792..b21a00c 100644 --- a/src/backend/targets/print/print.h +++ b/src/backend/targets/print/print.h @@ -25,6 +25,7 @@ void print_ast_translation_unit(struct AST_Translation_Unit *tree); void print_ast_binary_expression(struct AST_Binary_Expression *tree); void print_ast_unary_expression(struct AST_Unary_Expression *tree); void print_ast_unchecked_state(struct AST_Unchecked_State *tree); +void print_ast_if_statement(struct AST_If_Statement *tree); void print_error(struct Error *error); void print_errors(struct Translation_Data *translation_data); -- cgit v1.2.3