/* * Program to read in a description of a Finite State Automaton, * then decide if the string on the standard input is accepted. */ #include #define NUM_STATES 10 #define ALPHA_SIZE 2 int main (int argc, char *argv[]) { FILE *f; int changes[NUM_STATES][ALPHA_SIZE]; int state, state2, ch, initial, final, i; if (argc != 2) { fprintf (stderr, "give file name\n"); exit (1); } f = fopen (argv[1], "r"); final = 0; initial = NUM_STATES; while (!feof (f)) { fscanf (f, "%d", &state); for (i=0; i final) final = state; if (state < initial) initial = state; } } fclose (f); ch = getchar (); state = initial; while (ch != '$') { state = changes[state][ch - 'a']; ch = getchar (); } if (state == final) printf ("accepted.\n"); else printf ("not accepted.\n"); }