#include #include typedef char word[10]; enum state {start, art1, adj1, noun1, prep1, art2, adj2, noun2, verb, padj, part, pnoun, prep2, art3, adj3, noun3, done}; void searchfor (word, word[], int &); int main () { word list[29] = {"a", "an", "the", "huge", "polite", "green", "shifty", "tired", "mean", "nice", "speckled", "rough", "innocent", "dog", "horse", "Linda", "Donald", "elephant", "snail", "chicken", "with", "on", "by", "eats", "is", "stands", "calls", "feeds", "."}; word one; state at; ifstream infile; char filename[30]; int position; int stopper; int num = 0; cout << "Enter file name: "; cin >> filename; infile.open(filename); infile >> one; while (infile) { at = start; stopper = 0; while (at != done && stopper == 0) { searchfor(one, list, position); // cout << (int) at << ' ' << position << "p "; switch (at) { case start: case prep1: case prep2: if (position < 3) at = (state) (at + 1); else if (position < 13) at = (state) (at + 2); else if (position < 20) at = (state) (at + 3); else stopper = 1; break; case art1: case art2: case art3: if (position > 2 && position < 13) at = (state) (at + 1); else if (position > 12 && position < 20) at = (state) (at + 2); else stopper = 1; break; case adj1: case adj2: case adj3: if (position > 2 && position < 13) ; else if (position > 12 && position < 20) at = (state) (at + 1); else stopper = 1; break; case noun1: if (position > 19 && position < 23) at = prep1; else if (position > 22 && position < 28) at = verb; else stopper = 1; break; case noun2: if (position > 22 && position < 28) at = verb; else stopper = 1; break; case verb: if (position < 3) at = part; else if (position < 13) at = padj; else if (position < 20) at = pnoun; else if (position > 19 && position < 23) at = prep2; else stopper = 1; break; case part: if (position > 12 && position < 20) at = pnoun; else stopper = 1; break; case padj: case pnoun: case noun3: if (position == 28) at = done; else stopper = 1; } if (at != done && stopper == 0) infile >> one; } num++; if (at == done) cout << "Sentence " << num << " is VALID\n"; else cout << "Sentence " << num << " is NOT in the language\n"; if (position != 28) infile.ignore(200, '.'); infile >> one; } infile.close(); return 0; } void searchfor (word val, word group[], int& found) { for (found = 0; found < 29; found++) if (strcmp(val, group[found]) == 0) break; }