#include #include #include #include "lkb-protocol.h" #include "lui-genchart.h" parse_genedge(char **INPUT, int *TYPE, void **DATA) { int id_type, root_type, eplist_type, yield_type; char *yield; int id, root; char *p = *INPUT; char c; lui_genedge *e=0; lui_list *ep_list; *DATA = 0; //debug("parsing edge at %s\n", *INPUT); c = tokenize(&p); if(c!='[') { fprintf(stderr, "Expected '[' opening genedge structure\n"); goto done_edge; } parse_protocol(&p, &id_type, (void**)&id); if(id_type != type_int) { fprintf(stderr, "ID of edge was not a number (type %d)\n", id_type); goto done_edge; } parse_protocol(&p, &root_type, (void**)&root); if(root_type != type_int) { fprintf(stderr, "Rootness of edge was not a number (type %d)\n", root_type); goto done_edge; } parse_protocol(&p, &eplist_type, (void**)&ep_list); if(eplist_type != type_list) { fprintf(stderr, "EP list was not a list (type %d)\n", eplist_type); goto done_edge; } if(ep_list->type == -1)ep_list->type = type_int; if(ep_list->type != type_int) { fprintf(stderr, "EP list was not a list of numbers (type %d)\n", ep_list->type); goto done_edge; } parse_protocol(&p, &yield_type, (void**)&yield); if(yield_type != type_string) { fprintf(stderr, "Yield of edge was not a string (type %d)\n", yield_type); goto done_edge; } c = tokenize(&p); if(c!=']') { fprintf(stderr, "Expected ']' closing genedge structure\n"); goto done_edge; } e = (lui_genedge*)calloc(sizeof(lui_genedge), 1); e->id = id; e->root = root; e->yield = yield; e->ep_list = ep_list; done_edge: *TYPE = type_genedge; *INPUT=p; if(!e) { e = (lui_genedge*)calloc(sizeof(lui_genedge), 1); e->id = -1; e->root = -1; e->yield = strdup("ERR"); e->ep_list = calloc(sizeof(struct lui_list),1); } *(lui_genedge**)DATA = e; return 0; } lui_genchart *build_genchart(int id, int neps, char **eps, int nedges, struct lui_genedge **edges) { lui_genchart *c = calloc(sizeof(*c),1); c->id = id; c->neps = neps; c->eps = eps; c->nedges = nedges; c->edges = edges; return c; }