int main(int argc, char* argv[]) { int n,i; int last_pipe[2]; struct grammar g; if (argc != 4) { fatal("Usage: %s <workers number> <grammar file> <starting symbol>\n", argv[0]); } n = atoi(argv[1]); if (n <= 0) { fatal("Number of workers should be a positive integer"); } if (strlen(argv[3]) != 1 || !is_upper(argv[3][0])) { fatal("Starting symbol should be a single nonterminal (uppercase)\n"); } create_pipe(last_pipe); make_loop(n, last_pipe, argv[2]); read_grammar(&g, argv[2]); work(&g, argv[3][0]); for (i = 1; i < n; i++) { if (wait(0) == -1) syserr("Error in wait()\n"); } return 0; }
void make_loop(int n, int* last_pipe, char* grammar) { /* last_pipe[0] = input of the recently created pipe * * last_pipe[1] = output of the first pipe */ pid_t pid; if (n == 1) { prepare_input(last_pipe); prepare_output(last_pipe); close_pipe(last_pipe); return; } int next_pipe[2]; create_pipe(next_pipe); switch (pid = fork()) { case -1: syserr("Error in fork()\n"); case 0: prepare_input(last_pipe); close_pipe(last_pipe); prepare_output(next_pipe); close_pipe(next_pipe); execl("./worker", "./worker", grammar, NULL); syserr("Error in execl()\n"); default: last_pipe[0] = next_pipe[0]; make_loop(n - 1, last_pipe, grammar); return; } }
static void flow_find_loops (flowgraph_t *graph) { flownode_t *node; set_iter_t *succ; flowloop_t *loop, *l; flowloop_t *loop_list = 0; int i; for (i = 0; i < graph->num_nodes; i++) { node = graph->nodes[i]; for (succ = set_first (node->successors); succ; succ = set_next (succ)) { if (set_is_member (node->dom, succ->element)) { loop = make_loop (graph, node->id, succ->element); for (l = loop_list; l; l = l->next) { if (l->head == loop->head && !set_is_subset (l->nodes, loop->nodes) && !set_is_subset (loop->nodes, l->nodes)) { set_union (l->nodes, loop->nodes); delete_loop (loop); loop = 0; break; } } if (loop) { loop->next = loop_list; loop_list = loop; } } } } graph->loops = loop_list; }
uint build_helper(std::vector<Node>& tree, const Pos& pos) { // parse nodes in the depth first order if (vt_(pos.first, pos.second)==static_cast<uint>(-1)) { if (pos.first==pos.second) { make_leaf(tree, pos); } else if (bp_(pos).empty()) { make_loop(tree, pos); } else { make_stem(tree, pos); } } return vt_(pos.first, pos.second); }
DFA *dfaProduct(DFA* a1, DFA* a2, dfaProductType ff) { DFA *b; int i; unsigned *root_ptr; char binfun[4]; int make_a_loop; unsigned size_estimate = 4 + 4 * (bdd_size(a1->bddm) > bdd_size(a2->bddm) ? bdd_size(a1->bddm) : bdd_size(a2->bddm)); bdd_manager *bddm; /* #define _AUTOMATON_HASHED_IN_PRODUCT_ */ #ifdef _AUTOMATON_HASHED_IN_PRODUCT_ /*prepare hashed access */ bddm = bdd_new_manager(size_estimate, size_estimate/8 + 2); bdd_make_cache(bddm, size_estimate, size_estimate/8 + 2); bddm->cache_erase_on_doubling = TRUE ; #else /*prepare sequential access*/ bddm = bdd_new_manager(size_estimate, 0); bdd_make_cache(bddm, size_estimate, size_estimate/8 + 2); #endif binfun[0] = ff&1; binfun[1] = (ff&2)>>1; /* The binary function */ binfun[2] = (ff&4)>>2; binfun[3] = (ff&8)>>3; qst = qh = qt = new_list(a1->s, a2->s, (list) 0); htbl = new_hash_tab(&hash2, &eq2); insert_in_hash_tab(htbl, a1->s, a2->s, (void *) 1); last_state = 1; /* Careful here! Bdd's start at 0, hashtbl at 1 */ while(qh) { /* Our main loop, nice and tight */ make_a_loop = make_a_loop_status(is_loop(a1->bddm, qh->li1, a1->q[qh->li1]), a1->f[qh->li1], is_loop(a2->bddm, qh->li2, a2->q[qh->li2]), a2->f[qh->li2], binfun); if (make_a_loop != 2) make_loop(bddm, qh->li1, qh->li2); else { #ifdef _AUTOMATON_HASHED_IN_PRODUCT_ (void) bdd_apply2_hashed (a1->bddm, a1->q[qh->li1], a2->bddm, a2->q[qh->li2], bddm, &prod_term_fn); #else (void) bdd_apply2_sequential (a1->bddm, a1->q[qh->li1], a2->bddm, a2->q[qh->li2], bddm, &prod_term_fn); #endif } qh = qh->next; } b = dfaMakeNoBddm(last_state); /* Return the result */ b->s = 0; /* Always first on list */ b->bddm = bddm; for (i=0, root_ptr = bdd_roots(bddm); i < last_state; root_ptr++, i++) { list qnxt; b->q[i] = *root_ptr; b->f[i] = ((a1->f[qst->li1] != 0) && (a2->f[qst->li2] != 0)) ? /* both states are non-bottom, use "binfun" */ BOOL_TO_STATUS(binfun[STATUS_TO_BOOL(a1->f[qst->li1])*2 + STATUS_TO_BOOL(a2->f[qst->li2])]) : /* at least one is bottom */ 0; qnxt = qst->next; mem_free(qst); /* Free the list */ qst = qnxt; } free_hash_tab(htbl); bdd_update_statistics(bddm, (unsigned) PRODUCT); bdd_kill_cache(b->bddm); return(b); }