From 76fc38b3cdfded2911b464baa7b182b5102318d1 Mon Sep 17 00:00:00 2001 From: Galin Simeonov Date: Thu, 3 Jun 2021 12:38:37 +0300 Subject: work on generated C code --- src/frontend/parser.h | 46 +++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 43 insertions(+), 3 deletions(-) (limited to 'src/frontend/parser.h') diff --git a/src/frontend/parser.h b/src/frontend/parser.h index eaede84..74f2ed8 100644 --- a/src/frontend/parser.h +++ b/src/frontend/parser.h @@ -5,6 +5,9 @@ #include #include +#define AS_BIN_EXPR_PTR(x) ((struct AST_Binary_Expression*)x) +#define AS_UN_EXPR_PTR(x) ((struct AST_Unary_Expression*)x) +#define AS_UNCK_EXPR_PTR(x) ((struct AST_Unchecked_State*)x) enum AST_Type { AST_TYPE_TRANSLATION_UNIT, @@ -17,6 +20,11 @@ enum AST_Type AST_TYPE_TRANSITIONS, AST_TYPE_COMMAND, AST_TYPE_PIPELINE, + AST_TYPE_OP_AND, + AST_TYPE_OP_OR, + AST_TYPE_OP_NOT, + AST_TYPE_OP_SELECTOR, + AST_TYPE_UNFINISHED_STATE, }; struct AST { @@ -48,7 +56,7 @@ struct AST_Events struct AST_Transition { enum AST_Type type; - struct AST_State *from; + struct AST *from; struct AST_State *to; struct AST_Event *event; struct AST_Pipeline *pipeline; @@ -75,6 +83,7 @@ struct AST_Machine { enum AST_Type type; struct token *id; + struct AST_State *starting_state; struct AST_States *states; struct AST_Events *events; struct AST_Transitions *transitions; @@ -83,9 +92,26 @@ struct AST_Translation_Unit { enum AST_Type type; struct Map *used_commands_map; + struct Map *machines_map; size_t number_of_machines; struct AST_Machine *machines[]; }; +struct AST_Binary_Expression +{ + enum AST_Type type; + struct AST *left; + struct AST *right; +}; +struct AST_Unary_Expression +{ + enum AST_Type type; + struct AST *operand; +}; +struct AST_Unchecked_State +{ + enum AST_Type type; + struct token *name; +}; struct AST* parse_source(struct Translation_Data *translation_data); @@ -102,18 +128,28 @@ struct AST_Pipeline* parse_pipeline(struct Translation_Data *translation_data); struct AST_Command* parse_command(struct Translation_Data *translation_data); struct AST_State* parse_start_on(struct Translation_Data *translation_data,struct AST_States *states); +struct AST* parse_expression(struct Translation_Data *translation_data); +struct AST* parse_or_expression(struct Translation_Data *translation_data); +struct AST* parse_and_expression(struct Translation_Data *translation_data); +struct AST* parse_not_expression(struct Translation_Data *translation_data); +struct AST* parse_primary_expression(struct Translation_Data *translation_data); struct AST_State* get_ast_state(struct token *id); struct AST_Event* get_ast_event(struct token *id); struct AST_States* get_ast_states(struct Queue *states); struct AST_Events* get_ast_events(struct Queue *events); -struct AST_Transition* get_ast_transition(struct AST_State *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_Command* get_ast_command(struct token *function_name,struct token *argument); struct AST_Pipeline* get_ast_pipeline(struct Queue *pipeline); struct AST_Machine* get_ast_machine(struct token *id,struct AST_States *states,struct AST_Events *events,struct AST_Transitions *transitions,struct AST_State *starting_state); struct AST_Transitions* get_ast_transitions(struct Queue *transitions); -struct AST_Translation_Unit* get_ast_translation_unit(struct Queue *machines,struct Map *command_map); +struct AST_Translation_Unit* get_ast_translation_unit(struct Queue *machines,struct Map *command_map,struct Map *machines_map); + +struct AST_Binary_Expression* get_ast_binary_expression(struct AST *left,struct AST *right,enum AST_Type type); +struct AST_Unary_Expression* get_ast_unary_expression(struct AST *operand,enum AST_Type type); +struct AST_Unchecked_State* get_ast_unchecked_state(struct token *name); +struct AST_State* ast_check_state(struct AST_Unchecked_State *state,struct AST_States *states,struct Translation_Data *translation_data); void delete_ast(struct AST* ast); void delete_ast_event(struct AST_Event* ast); @@ -127,6 +163,10 @@ void delete_ast_machine(struct AST_Machine* ast); void delete_ast_transitions(struct AST_Transitions* ast); void delete_ast_translation_unit(struct AST_Translation_Unit *ast); +void delete_ast_binary_expression(struct AST_Binary_Expression *ast); +void delete_ast_unary_expression(struct AST_Unary_Expression *ast); +void delete_ast_unchecked_state(struct AST_Unchecked_State *ast); + void pointer_array_fill(void **array,struct Queue *q); struct Queue* parse_list(struct AST *(*parser)(struct Translation_Data*),struct Translation_Data *translation_data,enum Keyword delim); -- cgit v1.2.3