aboutsummaryrefslogtreecommitdiffstats
path: root/src/backend/backend.c
diff options
context:
space:
mode:
authorGalin Simeonov <gts@volconst.com>2021-06-04 13:04:36 +0300
committerGalin Simeonov <gts@volconst.com>2021-07-15 18:04:02 +0300
commitb845e4754be86d2216733d9bea75cb301f38739d (patch)
tree5ba6355d1cb36b1bfaadf82781796b1c42b9202b /src/backend/backend.c
parent76fc38b3cdfded2911b464baa7b182b5102318d1 (diff)
downloadMEGATRON-b845e4754be86d2216733d9bea75cb301f38739d.tar.gz
added expressions and the if statement
Diffstat (limited to 'src/backend/backend.c')
-rw-r--r--src/backend/backend.c30
1 files changed, 16 insertions, 14 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