diff options
Diffstat (limited to 'src/backend')
-rw-r--r-- | src/backend/backend.c | 30 | ||||
-rw-r--r-- | src/backend/targets/C/ast_to_c.c | 2 | ||||
-rw-r--r-- | src/backend/targets/C/ast_to_c.h | 2 | ||||
-rw-r--r-- | src/backend/targets/print/print.c | 97 | ||||
-rw-r--r-- | src/backend/targets/print/print.h | 4 |
5 files changed, 115 insertions, 20 deletions
diff --git a/src/backend/backend.c b/src/backend/backend.c index 6646e6c..512d247 100644 --- a/src/backend/backend.c +++ b/src/backend/backend.c @@ -43,7 +43,7 @@ struct State_And_Transitions** extract_transition_table(struct AST_States *state _Bool expression_is_binary(struct AST* expression) { - return (expression->type==AST_TYPE_OP_OR || expression->type==AST_TYPE_OP_AND); + return (expression->type==AST_TYPE_OP_OR || expression->type==AST_TYPE_OP_AND || expression->type==AST_TYPE_OP_SELECTOR); } _Bool expression_is_unary(struct AST* expression) { @@ -93,25 +93,23 @@ void anotate_unchecked_states(struct AST_Translation_Unit *unit,struct Translati size_t i; for(i=0;i<unit->number_of_machines;++i) { - anotate_machine(unit->machines[i],unit); + anotate_machine(unit->machines[i],unit,translation_data); } - if(has_new_errors( - } void anotate_machine(struct AST_Machine *machine,struct AST_Translation_Unit *unit,struct Translation_Data *translation_data) { size_t i; for(i=0;i<machine->transitions->size;++i) { - machine->transitions->transitions[i]->from=anotate_expression(machine->transitions->transitions[i]->from,machine,unit); + machine->transitions->transitions[i]->from=anotate_expression(machine->transitions->transitions[i]->from,unit,machine,translation_data); } if(has_new_errors(translation_data)) { - push_error_with_token("in machine",translation_data,machine->id); + push_error_with_token("in machine",machine->id,translation_data); delete_ast_machine(machine); } } -struct AST* anotate_expression(struct AST *expression,struct AST_Translation_Unit *unit,struct AST_Machine *current_machine,struct Translation_Data *translation_data); +struct AST* anotate_expression(struct AST *expression,struct AST_Translation_Unit *unit,struct AST_Machine *current_machine,struct Translation_Data *translation_data) { struct AST_Machine *hold_machine; struct AST *hold_left; @@ -119,8 +117,8 @@ struct AST* anotate_expression(struct AST *expression,struct AST_Translation_Uni if(expression_is_binary(expression)) { - left=((struct AST_Binary_Expression*)expression)->left; - right=((struct AST_Binary_Expression*)expression)->right; + hold_left=((struct AST_Binary_Expression*)expression)->left; + hold_right=((struct AST_Binary_Expression*)expression)->right; if(expression->type==AST_TYPE_OP_SELECTOR) { @@ -132,20 +130,24 @@ struct AST* anotate_expression(struct AST *expression,struct AST_Translation_Uni return NULL; }else { - return ast_check_state(hold_right,hold_machine->states,translation_data); + hold_left=(struct AST*)ast_check_state((struct AST_Unchecked_State*)hold_right,hold_machine->states,translation_data); + ((struct AST_State*)hold_left)->parent=hold_machine; + return hold_left; } }else { - AS_BIN_EXPR_PTR(expression)->right=anotate_expression(AS_BIN_EXPR_PTR(expression)->right,machine,unit); - AS_BIN_EXPR_PTR(expression)->left=anotate_expression(AS_BIN_EXPR_PTR(expression)->left,machine,unit); + AS_BIN_EXPR_PTR(expression)->right=anotate_expression(AS_BIN_EXPR_PTR(expression)->right,unit,current_machine,translation_data); + AS_BIN_EXPR_PTR(expression)->left=anotate_expression(AS_BIN_EXPR_PTR(expression)->left,unit,current_machine,translation_data); return expression; } }else if(expression_is_unary(expression)) { - AS_UN_EXPR_PTR(expression)->operand=anotate_expression(AS_UN_EXPR_PTR(expression)->operand,machine,unit); + AS_UN_EXPR_PTR(expression)->operand=anotate_expression(AS_UN_EXPR_PTR(expression)->operand,unit,current_machine,translation_data); }else if(expression->type==AST_TYPE_UNFINISHED_STATE) { - return ast_check_state(AS_UNCK_EXPR_PTR(expression),machine->states,translation_data); + hold_left=(struct AST*)ast_check_state((struct AST_Unchecked_State*)expression,current_machine->states,translation_data); + ((struct AST_State*)hold_left)->parent=current_machine; + return hold_left; } } #endif diff --git a/src/backend/targets/C/ast_to_c.c b/src/backend/targets/C/ast_to_c.c index 79d6017..3ce923d 100644 --- a/src/backend/targets/C/ast_to_c.c +++ b/src/backend/targets/C/ast_to_c.c @@ -3,7 +3,7 @@ #include <ast_to_c.h> #include <print.h> -void ast_to_c(char *output_name,struct AST *tree) +void ast_to_c(char *output_name,struct AST_Translation_Unit *tree) { size_t output_name_length; char *hold_name; diff --git a/src/backend/targets/C/ast_to_c.h b/src/backend/targets/C/ast_to_c.h index 6e4006f..fb3e729 100644 --- a/src/backend/targets/C/ast_to_c.h +++ b/src/backend/targets/C/ast_to_c.h @@ -9,7 +9,7 @@ struct State_And_Transitions; -void ast_to_c(char *output_name,struct AST *tree); +void ast_to_c(char *output_name,struct AST_Translation_Unit *tree); void ast_translation_unit_to_c_print_header_part(FILE *out,char *base_name,struct AST_Translation_Unit *translation_unit); void ast_translation_unit_to_c_print_body_part(FILE *out,char *base_name,struct AST_Translation_Unit *translation_unit); 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;i<tree->number_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 diff --git a/src/backend/targets/print/print.h b/src/backend/targets/print/print.h index 54d47ce..d318792 100644 --- a/src/backend/targets/print/print.h +++ b/src/backend/targets/print/print.h @@ -21,6 +21,10 @@ void print_ast_command(struct AST_Command* tree); void print_ast_pipeline(struct AST_Pipeline* tree); void print_ast_machine(struct AST_Machine* tree); void print_ast_transitions(struct AST_Transitions* tree); +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_error(struct Error *error); void print_errors(struct Translation_Data *translation_data); |