Fixed infinite loop bug- Was attempting to see if a non-closured state and a closured state were equal, almost never were.
This commit is contained in:
@@ -18,6 +18,7 @@ class State {
|
|||||||
State(int number, ParseRule* basis);
|
State(int number, ParseRule* basis);
|
||||||
~State();
|
~State();
|
||||||
bool const operator==(const State &other);
|
bool const operator==(const State &other);
|
||||||
|
bool const basisEquals(const State &other);
|
||||||
bool const operator!=(const State &other);
|
bool const operator!=(const State &other);
|
||||||
std::vector<ParseRule*>* getBasis();
|
std::vector<ParseRule*>* getBasis();
|
||||||
std::vector<ParseRule*>* getRemaining();
|
std::vector<ParseRule*>* getRemaining();
|
||||||
|
|||||||
@@ -243,20 +243,22 @@ void Parser::addStates(std::vector< State* >* stateSets, State* state) {
|
|||||||
stateAlreadyInAllStates = false;
|
stateAlreadyInAllStates = false;
|
||||||
currStateSymbol = (*(newStates[i]->getBasis()))[0]->getAtIndex();
|
currStateSymbol = (*(newStates[i]->getBasis()))[0]->getAtIndex();
|
||||||
for (std::vector< State * >::size_type j = 0; j < stateSets->size(); j++) {
|
for (std::vector< State * >::size_type j = 0; j < stateSets->size(); j++) {
|
||||||
if (*(newStates[i]) == *((*stateSets)[j])) {
|
if (newStates[i]->basisEquals(*((*stateSets)[j]))) {
|
||||||
stateAlreadyInAllStates = true;
|
stateAlreadyInAllStates = true;
|
||||||
//If it does exist, we should add it as the shift/goto in the action table
|
//If it does exist, we should add it as the shift/goto in the action table
|
||||||
addToTable(state, currStateSymbol, new ParseAction(ParseAction::SHIFT, j));
|
|
||||||
std::cout << "State exists, is " << j << std::endl;
|
std::cout << "State exists, is " << j << std::endl;
|
||||||
|
addToTable(state, currStateSymbol, new ParseAction(ParseAction::SHIFT, j));
|
||||||
break;
|
break;
|
||||||
}
|
}/* else {
|
||||||
|
std::cout << "State " << newStates[i]->toString() << " does not equal " << (*stateSets)[j]->toString() << std::endl;
|
||||||
|
}*/
|
||||||
}
|
}
|
||||||
if (!stateAlreadyInAllStates) {
|
if (!stateAlreadyInAllStates) {
|
||||||
stateSets->push_back(newStates[i]);
|
stateSets->push_back(newStates[i]);
|
||||||
//If the state does not already exist, add it and add it as the shift/goto in the action table
|
//If the state does not already exist, add it and add it as the shift/goto in the action table
|
||||||
addToTable(state, currStateSymbol, new ParseAction(ParseAction::SHIFT, stateSets->size()-1));
|
|
||||||
std::cout << "State does not exist" << std::endl;
|
std::cout << "State does not exist" << std::endl;
|
||||||
std::cout << "State is " << newStates[i]->toString() << std::endl;
|
std::cout << "State is " << newStates[i]->toString() << std::endl;
|
||||||
|
addToTable(state, currStateSymbol, new ParseAction(ParseAction::SHIFT, stateSets->size()-1));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -329,7 +331,7 @@ void Parser::addToTable(State* fromState, Symbol* tranSymbol, ParseAction* actio
|
|||||||
//If the slot is not empty and does not contain ourself, then it is a conflict
|
//If the slot is not empty and does not contain ourself, then it is a conflict
|
||||||
else if ( *((*(table[stateNum]))[symbolIndex]) != *action) {
|
else if ( *((*(table[stateNum]))[symbolIndex]) != *action) {
|
||||||
//std::cout << "not Null!" << std::endl;
|
//std::cout << "not Null!" << std::endl;
|
||||||
std::cout << "Conflict between old: " << (*(table[stateNum]))[symbolIndex]->toString() << " and new: " << action->toString() << std::endl;
|
std::cout << "State: " << stateNum << " Conflict between old: " << (*(table[stateNum]))[symbolIndex]->toString() << " and new: " << action->toString() << std::endl;
|
||||||
//Don't overwrite
|
//Don't overwrite
|
||||||
//(*(table[stateNum]))[symbolIndex] = action;
|
//(*(table[stateNum]))[symbolIndex] = action;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,6 +32,18 @@ const bool State::operator!=(const State &other) {
|
|||||||
return !(this->operator==(other));
|
return !(this->operator==(other));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const bool State::basisEquals(const State &other) {
|
||||||
|
//return (basis == other.basis && remaining == other.remaining);
|
||||||
|
if (basis.size() != other.basis.size())
|
||||||
|
return false;
|
||||||
|
|
||||||
|
for (std::vector< ParseRule* >::size_type i = 0; i < basis.size(); i++) {
|
||||||
|
if (*(basis[i]) != *(other.basis[i]))
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
std::vector<ParseRule*>* State::getTotal() {
|
std::vector<ParseRule*>* State::getTotal() {
|
||||||
total.clear();
|
total.clear();
|
||||||
for (std::vector<ParseRule*>::size_type i = 0; i < basis.size(); i++) {
|
for (std::vector<ParseRule*>::size_type i = 0; i < basis.size(); i++) {
|
||||||
|
|||||||
Reference in New Issue
Block a user