diff options
author | Galin Simeonov <gts@volconst.com> | 2021-06-01 18:21:02 +0300 |
---|---|---|
committer | Galin Simeonov <gts@volconst.com> | 2021-07-15 18:03:43 +0300 |
commit | 85b23fbee717f047af5a89eac6f4dba8e7812524 (patch) | |
tree | dc88ef3f4cb826f4f3a3c9e12c67562878460aa5 /src/backend/backend.c | |
parent | 255a49ba5a41b3854dbdfebdec75fb6229450507 (diff) | |
download | MEGATRON-85b23fbee717f047af5a89eac6f4dba8e7812524.tar.gz |
restructuring
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 |