blob: 122e84c6dcf24475336d218d70efde50f0c6d1bf (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
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
|