-
Notifications
You must be signed in to change notification settings - Fork 39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Grammars Assignment #44
Conversation
r -> "r" <br> | ||
g -> "g" <br> | ||
b -> "b" <br> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No deduction; just for your information: no need for these last three lines: in the grammar, r, g, and b are already terminals.
Compile using: g++ -std=c++11 -o fsm fsm.cpp <br> | ||
Run using: ./fsm | ||
|
||
You can change the sentences in the "tests" function | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for writing positive and negative tests. However, as tests they don't quite go far enough. An automated test should both run the code and also verify that the result was what was expected. So, for example, your code could be:
vector<vector<string> > testSentences {
{"the", "dog", "ate", "EOI"},
{"the", "cat", "ate", "EOI"},
{"the", "smelly", "dog", "ate", "EOI"},
{"the", "lazy", "cat", "ran", "EOI"},
{"the", "smelly", "cat", "ate", "noisily", "EOI"},
{"the", "lazy", "dog", "ate", "slowly", "EOI"},
{"the", "lazy", "smelly", "smelly", "smelly", "dog", "ate", "EOI"},
{"the", "lazy", "dog", "barked", "noisily", "EOI"},
{"the", "dog", "ate"},
{"the", "EOI"}
};
bool expected[] = { true, true, true, true, true, true, true, false, false, false };
for(int i = 0; i < testSentences.size(); i++){
auto sentence = testSentences[i];
if(valid(sentence) == expected[i])
cout << "OK: ";
else
cout << "FAILED: expected " << expected[i] << "; ";
for (int i = 0; i < sentence.size(); i++) {
cout << sentence[i] << " ";
}
cout << endl;
}
-2
And then, just an observation. Clearly, C++ programmers are masochists, but even so... why
void initialization(){
//create a table with all the valid states and next states
table.insert(make_pair(make_pair(0, "the"), 1));
table.insert(make_pair(make_pair(1, "lazy"), 1));
table.insert(make_pair(make_pair(1, "smelly"), 1));
table.insert(make_pair(make_pair(1, "dog"), 2));
table.insert(make_pair(make_pair(1, "cat"), 2));
table.insert(make_pair(make_pair(2, "ate"), 3));
table.insert(make_pair(make_pair(2, "ran"), 3));
table.insert(make_pair(make_pair(3, "slowly"), 4));
table.insert(make_pair(make_pair(3, "noisily"), 4));
table.insert(make_pair(make_pair(3, "EOI"), 5));
table.insert(make_pair(make_pair(4, "EOI"), 5));
}
when you could write
map<pair<int, string>, int> table {
{{ 0, "the" }, 1},
{{ 1, "lazy" }, 1},
{{ 1, "smelly" }, 1},
{{ 1, "dog" }, 2},
{{ 1, "cat" }, 2},
{{ 2, "ate" }, 3},
{{ 2, "ran" }, 3},
{{ 3, "slowly" }, 4},
{{ 3, "noisily" }, 4},
{{ 3, "EOI" }, 5},
{{ 4, "EOI" }, 5},
};
Just sayin'
Nice job |
Harrison Noble
47475653