From 85b23fbee717f047af5a89eac6f4dba8e7812524 Mon Sep 17 00:00:00 2001 From: Galin Simeonov Date: Tue, 1 Jun 2021 18:21:02 +0300 Subject: restructuring --- src/backend/backend.c | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 src/backend/backend.c (limited to 'src/backend/backend.c') diff --git a/src/backend/backend.c b/src/backend/backend.c new file mode 100644 index 0000000..122e84c --- /dev/null +++ b/src/backend/backend.c @@ -0,0 +1,37 @@ +#ifndef BACKEND_C +#define BACKEND_C BACKEND_C +#include + +/*returns an array of pointers to state_and_transition structs*/ +struct State_And_Transitions** extract_transition_table(struct AST_States *states,struct AST_Transitions *transitions) +{ + struct State_And_Transitions **ret; + struct Queue *qs; + size_t i; + + ret=malloc(sizeof(struct State_And_Transitions)*states->number_of_states); + + /*calloc also initialises the queues + *i-th queue is for transitions starting from the i-th state + * */ + qs=calloc(sizeof(struct Queue),states->number_of_states); + + /*traverse transitions and push them into the queue of their coresponding state*/ + for(i=0;isize;++i) + Queue_Push(qs+transitions->transitions[i]->from->number,transitions->transitions[i]); + + /*condense the queues into the arrays*/ + for(i=0;inumber_of_states;++i) + { + ret[i]=malloc(sizeof(struct State_And_Transitions)+sizeof(struct AST_Transitions *[qs[i].size])); + ret[i]->state=states->states[i]; + ret[i]->number_of_transitions=qs[i].size; + pointer_array_fill((void**)ret[i]->transitions,qs+i); + } + + free(qs); + + return ret; +} + +#endif -- cgit v1.2.3