#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