diff options
Diffstat (limited to 'src/backend/backend.c')
-rw-r--r-- | src/backend/backend.c | 37 |
1 files changed, 37 insertions, 0 deletions
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 <backend.h> + +/*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;i<transitions->size;++i) + Queue_Push(qs+transitions->transitions[i]->from->number,transitions->transitions[i]); + + /*condense the queues into the arrays*/ + for(i=0;i<states->number_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 |