Extended the Regular Expression class to now support * and ? as well as +. Next up, perens and alternation

This commit is contained in:
Nathan Braswell
2013-07-03 23:40:36 -04:00
parent cc6ff21986
commit 84566c4ff6
2 changed files with 68 additions and 8 deletions

View File

@@ -29,21 +29,30 @@ bool RegExState::characterIs(char inCharacter) {
std::vector<RegExState*>* RegExState::advance(char advanceCharacter) {
std::vector<RegExState*>* advanceStates = new std::vector<RegExState*>();
for (std::vector<RegExState*>::size_type i = 0; i < nextStates.size(); i++) {
if (nextStates[i]->characterIs(advanceCharacter))
if (nextStates[i] != NULL && nextStates[i]->characterIs(advanceCharacter))
advanceStates->push_back(nextStates[i]);
}
return advanceStates;
}
bool RegExState::isGoal() {
return inner == NULL && nextStates.size() == 0;
//return inner == NULL && nextStates.size() == 0;
for (std::vector<RegExState*>::size_type i = 0; i < nextStates.size(); i++)
if (nextStates[i] == NULL)
return true;
return false;
}
std::string RegExState::toString() {
std::string string = "";
string += std::string("\"") + character + "\"";
for (std::vector<RegExState*>::size_type i = 0; i < nextStates.size(); i++)
string += "->" + nextStates[i]->toString() + " EC ";
if (nextStates[i] != this && nextStates[i] != NULL)
string += "->" + nextStates[i]->toString() + " EC ";
else if (nextStates[i] == NULL)
string += "-> GOAL ";
else
string += "->this";
//std::cout << "inner = " << inner << " nextStates size = " << nextStates.size() <<std::endl;
return string;
}