aboutsummaryrefslogtreecommitdiffstats
path: root/src/frontend/parser.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/frontend/parser.c
parent76fc38b3cdfded2911b464baa7b182b5102318d1 (diff)
downloadMEGATRON-b845e4754be86d2216733d9bea75cb301f38739d.tar.gz
added expressions and the if statement
Diffstat (limited to 'src/frontend/parser.c')
-rw-r--r--src/frontend/parser.c36
1 files changed, 25 insertions, 11 deletions
diff --git a/src/frontend/parser.c b/src/frontend/parser.c
index a260622..fa692f5 100644
--- a/src/frontend/parser.c
+++ b/src/frontend/parser.c
@@ -25,7 +25,6 @@ struct AST_Translation_Unit* parse_translation_unit(struct Translation_Data *tra
Map_Init(hold_machines_map);
translation_data->hold_command_map=hold_command_map;
- translation_data->hold_machines_map=hold_machines_map;
while(!get_and_check(translation_data,KW_EOF))
{
@@ -332,7 +331,7 @@ struct AST_Transitions* parse_transitions_inner(struct Translation_Data *transla
struct AST_Transition* parse_transition(struct Translation_Data *translation_data,struct AST_States *states,struct AST_Events *events)
{
struct AST_Transition *ret;
- struct AST_State *hold_from;
+ struct AST *hold_from;
struct AST_State *hold_to;
struct AST_Event *hold_event;
struct AST_Pipeline *hold_pipeline=NULL;
@@ -448,9 +447,11 @@ struct AST_State* get_ast_state(struct token *id)
struct AST_State *ret;
ret=malloc(sizeof(struct AST_State));
+ ret->type=AST_TYPE_STATE;
ret->name=id;
/*number is assigned in get_ast_states*/
+ /*parent machine is determined in anotation stage*/
return ret;
}
@@ -522,7 +523,7 @@ struct AST_Events* get_ast_events(struct Queue *events)
return ret;
}
-struct AST_Transition* get_ast_transition(struct AST *from,struct AST_State *to,struct AST_Event *event,struct AST_Pipeline *pipeline);
+struct AST_Transition* get_ast_transition(struct AST *from,struct AST_State *to,struct AST_Event *event,struct AST_Pipeline *pipeline)
{
struct AST_Transition *ret;
ret=malloc(sizeof(struct AST_Transition));
@@ -617,6 +618,21 @@ void delete_ast(struct AST* ast)
case AST_TYPE_PIPELINE:
delete_ast_pipeline((struct AST_Pipeline*)ast);
break;
+ case AST_TYPE_TRANSLATION_UNIT:
+ delete_ast_translation_unit((struct AST_Translation_Unit*)ast);
+ break;
+ case AST_TYPE_OP_AND:
+ case AST_TYPE_OP_OR:
+ case AST_TYPE_OP_SELECTOR:
+ delete_ast_binary_expression((struct AST_Binary_Expression*)ast);
+ break;
+ case AST_TYPE_OP_NOT:
+ delete_ast_unary_expression((struct AST_Unary_Expression*)ast);
+ break;
+ case AST_TYPE_UNFINISHED_STATE:
+ delete_ast_unchecked_state((struct AST_Unchecked_State*)ast);
+ break;
+
}
}
void delete_ast_event(struct AST_Event* ast)
@@ -660,8 +676,6 @@ void delete_ast_pipeline(struct AST_Pipeline* ast)
{
size_t i;
if(ast==NULL)return;
- for(i=0;i<ast->size;++i)
- delete_ast_command(ast->pipeline[i]);
free(ast);
}
void delete_ast_machine(struct AST_Machine* ast)
@@ -773,7 +787,7 @@ struct AST* parse_or_expression(struct Translation_Data *translation_data)
delete_ast(hold_left_expression);
return NULL;
}
- return (struct AST*)get_ast_binary_expression(left,right,AST_TYPE_OP_OR);
+ return (struct AST*)get_ast_binary_expression(hold_left_expression,hold_right_expression,AST_TYPE_OP_OR);
}else
{
return hold_left_expression;
@@ -801,7 +815,7 @@ struct AST* parse_and_expression(struct Translation_Data *translation_data)
delete_ast(hold_left_expression);
return NULL;
}
- return (struct AST*)get_ast_binary_expression(left,right,AST_TYPE_OP_AND);
+ return (struct AST*)get_ast_binary_expression(hold_left_expression,hold_right_expression,AST_TYPE_OP_AND);
}else
{
return hold_left_expression;
@@ -818,7 +832,7 @@ struct AST* parse_not_expression(struct Translation_Data *translation_data)
hold_expression=parse_primary_expression(translation_data);
if(hold_expression!=NULL)
{
- return get_ast_unary_expression(hold_expression,AST_TYPE_OP_NOT);
+ return (struct AST*)get_ast_unary_expression(hold_expression,AST_TYPE_OP_NOT);
}else
{
push_parsing_error("in '!' expression",translation_data);
@@ -857,16 +871,16 @@ struct AST* parse_primary_expression(struct Translation_Data *translation_data)
if(get_kw(translation_data)==KW_ID)
{
hold_id2=get_ast_unchecked_state(Queue_Pop(translation_data->tokens));
- return get_ast_binary_expression(hold_id1,hold_id2,AST_TYPE_OP_SELECTOR);
+ return (struct AST*)get_ast_binary_expression((struct AST*)hold_id1,(struct AST*)hold_id2,AST_TYPE_OP_SELECTOR);
}else
{
push_parsing_error("expected a state id in selector",translation_data);
- delete_ast(hold_id1);
+ delete_ast((struct AST*)hold_id1);
return NULL;
}
}else
{
- return hold_id1;
+ return (struct AST*)hold_id1;
}
}else
{