/* fsacount.c 27/10/94. * 20/3/96 - added "-is n" option, to change the initial state of the fsa to * n (useful for coset reduction automata). * * Counts the accepted language of a fsa * This outputs to stdout only. * * SYNOPSIS: fsacount [-is n] [-ip d/s] [-silent] [-v] [filename]\n"); * * Input is from filename or stdin, which should contain a fsa. * * OPTIONS: * -is n change initial state of fsa to n. * -ip d/s input in dense or sparse format - dense is default * -v verbose * -silent no diagnostics
*/
inf[0] = '\0';
n = 0;
arg = 1; while (argc > arg) { if (strcmp(argv[arg], "-is") == 0) {
arg++; if (arg >= argc)
badusage();
n = atoi(argv[arg]);
} elseif (strcmp(argv[arg], "-ip") == 0) {
arg++; if (arg >= argc)
badusage(); if (strcmp(argv[arg], "d") == 0)
ip_store = DENSE; elseif (argv[arg][0] == 's')
ip_store = SPARSE; else
badusage();
} elseif (strcmp(argv[arg], "-silent") == 0)
kbm_print_level = 0; elseif (strcmp(argv[arg], "-v") == 0)
kbm_print_level = 2; elseif (strcmp(argv[arg], "-vv") == 0)
kbm_print_level = 3; else { if (argv[arg][0] == '-')
badusage(); if (strcmp(inf, ""))
badusage();
strcpy(inf, argv[arg]);
}
arg++;
} if (stringlen(inf) == 0)
rfile = stdin; elseif ((rfile = fopen(inf, "r")) == 0) {
fprintf(stderr, "Cannot open file %s.\n", inf); exit(1);
}
fsa_read(rfile, &testfsa, ip_store, 0, 0, TRUE, fsaname); if (stringlen(inf))
fclose(rfile); if (n > testfsa.states->size) {
fprintf(stderr, "Error: specified initial state is too large.\n"); exit(1);
} if (n > 0 && testfsa.num_initial > 0) {
testfsa.initial[1] = n; /* This may destroy various properties of the automata */
testfsa.flags[MINIMIZED] = FALSE;
testfsa.flags[BFS] = FALSE;
testfsa.flags[ACCESSIBLE] = FALSE;
testfsa.flags[TRIM] = FALSE;
}
ct = fsa_count(&testfsa); if (ct == -1) exit(1); if (ct == -2)
printf("#The language accepted is infinite.\n"); else
printf("#The language accepted has size %d.\n", ct);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.