From b845e4754be86d2216733d9bea75cb301f38739d Mon Sep 17 00:00:00 2001 From: Galin Simeonov Date: Fri, 4 Jun 2021 13:04:36 +0300 Subject: added expressions and the if statement --- src/backend/targets/print/print.c | 97 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 93 insertions(+), 4 deletions(-) (limited to 'src/backend/targets/print/print.c') diff --git a/src/backend/targets/print/print.c b/src/backend/targets/print/print.c index 8eae3dd..7649b91 100644 --- a/src/backend/targets/print/print.c +++ b/src/backend/targets/print/print.c @@ -36,6 +36,12 @@ void print_keyword_enum(enum Keyword code) case KW_CLOSE_SQUARE: printf("KW_CLOSE_SQUARE"); break; + case KW_OPEN_NORMAL: + printf("KW_OPEN_NORMAL"); + break; + case KW_CLOSE_NORMAL: + printf("KW_CLOSE_NORMAL"); + break; case KW_PIPE: printf("KW_PIPE"); break; @@ -54,15 +60,27 @@ void print_keyword_enum(enum Keyword code) case KW_EVENT: printf("KW_EVENT"); break; - case KW_TRANSITIONS: - printf("KW__TRANSITIONS"); - break; case KW_EXECUTE: printf("KW_EXECUTE"); break; + case KW_TRANSITIONS: + printf("KW_TRANSITIONS"); + break; case KW_COMMA: printf("KW_COMMA"); break; + case KW_DOT: + printf("KW_DOT"); + break; + case KW_AND: + printf("KW_AND"); + break; + case KW_OR: + printf("KW_OR"); + break; + case KW_NOT: + printf("KW_NOT"); + break; default: printf("LEXERROR"); } @@ -95,6 +113,9 @@ void print_ast_enum(enum AST_Type type) { switch(type) { + case AST_TYPE_TRANSLATION_UNIT: + printf("AST_TYPE_TRANSLATION_UNIT"); + break; case AST_TYPE_MACHINE: printf("AST_TYPE_MACHINE"); break; @@ -122,6 +143,21 @@ void print_ast_enum(enum AST_Type type) case AST_TYPE_PIPELINE: printf("AST_TYPE_PIPELINE"); break; + case AST_TYPE_OP_AND: + printf("AST_TYPE_OP_AND"); + break; + case AST_TYPE_OP_OR: + printf("AST_TYPE_OP_OR"); + break; + case AST_TYPE_OP_NOT: + printf("AST_TYPE_OP_NOT"); + break; + case AST_TYPE_OP_SELECTOR: + printf("AST_TYPE_OP_SELECTOR"); + break; + case AST_TYPE_UNFINISHED_STATE: + printf("AST_TYPE_UNFINISHED_STATE"); + break; default: printf("AST_NOP"); } @@ -160,6 +196,20 @@ void print_ast(struct AST *tree) case AST_TYPE_PIPELINE: print_ast_pipeline((struct AST_Pipeline*)tree); break; + case AST_TYPE_TRANSLATION_UNIT: + print_ast_translation_unit((struct AST_Translation_Unit*)tree); + break; + case AST_TYPE_OP_AND: + case AST_TYPE_OP_OR: + case AST_TYPE_OP_SELECTOR: + print_ast_binary_expression((struct AST_Binary_Expression*)tree); + break; + case AST_TYPE_OP_NOT: + print_ast_unary_expression((struct AST_Unary_Expression*)tree); + break; + case AST_TYPE_UNFINISHED_STATE: + print_ast_unchecked_state((struct AST_Unchecked_State*)tree); + break; default: printf("noast"); } @@ -212,7 +262,7 @@ void print_ast_transition(struct AST_Transition* tree) assert(tree); printf("TRANSITION [\nFROM"); - print_ast_state(tree->from); + print_ast(tree->from); printf(" TO "); print_ast_state(tree->to); printf(" COMMAND {"); @@ -292,4 +342,43 @@ void print_errors(struct Translation_Data *translation_data) print_error(it->data); } } +void print_ast_translation_unit(struct AST_Translation_Unit *tree) +{ + size_t i; + printf("TRANSLATION UNIT\n[\n"); + for(i=0;inumber_of_machines;++i) + print_ast_machine(tree->machines[i]); + printf("\n] TRANSLATION UNIT END \n"); +} +void print_ast_binary_expression(struct AST_Binary_Expression *tree) +{ + printf(" ("); + print_ast(tree->left); + switch(tree->type) + { + case AST_TYPE_OP_AND: + printf("&&"); + break; + case AST_TYPE_OP_OR: + printf("||"); + break; + case AST_TYPE_OP_SELECTOR: + printf("."); + break; + default: + printf("?!!?!?!?"); + } + print_ast(tree->right); + printf(")"); +} +void print_ast_unary_expression(struct AST_Unary_Expression *tree) +{ + printf("(!"); + print_ast(tree->operand); + printf(")"); +} +void print_ast_unchecked_state(struct AST_Unchecked_State *tree) +{ + print_token(tree->name); +} #endif -- cgit v1.2.3