int main() { wPDS *pds; wFA *fa, *fa_pre; wPath *p; wSemiring sr = { &nullfn,&nullfn,NULL,&null,&null,NULL,&eqfn,NULL,NULL }; /* extend, combine, diff, one, zero, q-one, eq, ref, deref */ wSemiring *s = &sr; wIdent k_x,k_h,k_aids,k_im,k_alice; wIdent y_patient, y_square, y_bsquare; wIdent final_state; wInit(); k_x = wIdentCreate("KX"); k_h = wIdentCreate("KH"); k_aids = wIdentCreate("KH-AIDS"); k_im = wIdentCreate("KH-IM"); k_alice = wIdentCreate("Alice"); y_patient = wIdentCreate("patient"); y_square = wIdentCreate("square"); y_bsquare = wIdentCreate("b_square"); final_state = wIdentCreate("__accepting_state__"); pds = wPDSCreate(s); wPDSInsert(pds, k_x, y_square, k_h, y_patient, y_bsquare, NULL); wPDSInsert(pds, k_h, y_patient, k_im, y_patient, 0, NULL); wPDSInsert(pds, k_h, y_patient, k_aids, y_patient, 0, NULL); wPDSInsert(pds, k_im, y_patient, k_alice, 0, 0, NULL); wPDSInsert(pds, k_aids, y_patient, k_alice, 0, 0, NULL); fa = wFACreate(s); wFAInsert(fa,k_alice, y_square , final_state, NULL, NULL); wFAInsert(fa,k_alice, y_bsquare , final_state, NULL, NULL); print_automaton(fa,"before"); fa_pre = wPrestar(pds,fa,TRACE_YES); print_automaton(fa_pre,"after"); printf("trace example:\n"); p = wPathCreate(fa_pre,wFAFind(fa_pre,k_x,y_square,final_state),NULL); print_trace(fa_pre,p); wPDSDelete(pds); wFADelete(fa); wFADelete(fa_pre); wFinish(); return 0; } /** end of main **/
int main () { Automaton *a = create_automaton(); int e0 = add_state(a); int e1 = add_state(a); int e2 = add_state(a); set_initial(a, e1); set_final(a, e2); add_arc(a, e0, e1, 1); add_arc(a, e1, e1, 2); add_arc(a, e1, e2, 3); print_automaton(a); return 0; }
int test(){ /* * Warning: this test is leaky; All intermediate machines should be freed. */ FiniteAutomaton *j = create_automaton_char('j'); FiniteAutomaton *o = create_automaton_char('o'); FiniteAutomaton *g = create_automaton_char('g'); FiniteAutomaton *e = create_automaton_char('e'); FiniteAutomaton *blank = create_automaton_char(' '); FiniteAutomaton *dash = create_automaton_char('-'); print_automaton(dash); //Warning:leaky FiniteAutomaton *jiter, *middle, *full_last, *last, *lastiter, *total; jiter = create_automaton_iteration(j); middle = create_automaton_alternation(e, blank); full_last = create_automaton_concatenation(o, create_automaton_concatenation(dash, g)); last = create_automaton_concatenation(blank, create_automaton_alternation(o, full_last)); lastiter = create_automaton_iteration(last); total = create_automaton_concatenation(jiter, create_automaton_concatenation(middle, lastiter)); print_automaton(total); FiniteAutomaton *det; det = create_automaton_deterministic(total); print_automaton(det); char test_string[] = "jje o-g o o o-g"; int result = automaton_test_string(det, test_string, 15); printf("String match: \"%s\" : %d\n", test_string, result); /*FiniteAutomaton *a, *b, *c, *d, *e, *f; a = create_automaton_concatenation(j, o); b = create_automaton_alternation(j, o); c = create_automaton_alternation(b, g); d = create_automaton_iteration(j); e = create_automaton_iteration(c); //print_automaton(d); print_automaton(e); f = create_automaton_deterministic(e); print_automaton(f); delete_automaton(a); delete_automaton(b); delete_automaton(c); delete_automaton(d); delete_automaton(e); delete_automaton(f); delete_automaton(j); delete_automaton(o); delete_automaton(g); */ return 0; }