Now parses into parse trees! Still does not add the null-reducable trees, and there are a few ordering mistakes, but it works.

This commit is contained in:
Nathan Braswell
2013-08-10 18:24:37 -04:00
parent 9f3370481e
commit b292bd15ae
2 changed files with 10 additions and 10 deletions

View File

@@ -220,7 +220,7 @@ std::string NodeTree<T>::DOTGraphStringHelper() {
if (children[i] != NULL) if (children[i] != NULL)
ourDOTRelation += getDOTName() + " -> " + children[i]->getDOTName() + ";\n" + children[i]->DOTGraphStringHelper(); ourDOTRelation += getDOTName() + " -> " + children[i]->getDOTName() + ";\n" + children[i]->DOTGraphStringHelper();
else else
ourDOTRelation += getDOTName() + " -> BAD_NULL_" + getDOTName(); ourDOTRelation += getDOTName() + " -> BAD_NULL_" + getDOTName() + "\n";
} }
return(ourDOTRelation); return(ourDOTRelation);
} }

View File

@@ -101,10 +101,9 @@ NodeTree<Symbol*>* RNGLRParser::parseInput(std::string inputString) {
if (accState) { if (accState) {
std::cout << "Accepted!" << std::endl; std::cout << "Accepted!" << std::endl;
return gss.getEdge(accState, v0); return gss.getEdge(accState, v0);
} else {
std::cout << "Rejected!" << std::endl;
} }
std::cout << "Rejected!" << std::endl;
std::cout << "GSS:\n" << gss.toString() << std::endl; std::cout << "GSS:\n" << gss.toString() << std::endl;
return NULL; return NULL;
} }
@@ -119,18 +118,16 @@ void RNGLRParser::reducer(int i) {
for (std::vector<std::vector<NodeTree<int>*> >::size_type j = 0; j < paths->size(); j++) { for (std::vector<std::vector<NodeTree<int>*> >::size_type j = 0; j < paths->size(); j++) {
//Algorithm expects path in reverse order
std::vector<NodeTree<int>*> currentPath = (*paths)[j]; std::vector<NodeTree<int>*> currentPath = (*paths)[j];
std::reverse(currentPath.begin(), currentPath.end());
//Add label of first edge to the end, (since reversed, this is the correct place)
//Get the edges for the current path //Get the edges for the current path
std::vector<NodeTree<Symbol*>*> pathEdges = getPathEdges(currentPath); std::vector<NodeTree<Symbol*>*> pathEdges = getPathEdges(currentPath);
std::reverse(pathEdges.begin(), pathEdges.end());
//If the reduction length is 0, label as passed in is null //If the reduction length is 0, label as passed in is null
if (reduction.length != 0) if (reduction.length != 0)
pathEdges.push_back(reduction.label); pathEdges.push_back(reduction.label);
//The end of the current path (remember reversed) //The end of the current path
NodeTree<int>* currentReached = currentPath[0]; NodeTree<int>* currentReached = currentPath[currentPath.size()-1];
std::cout << "Getting the shfit state for state " << currentReached->getData() << " and symbol " << reduction.symbol->toString() << std::endl; std::cout << "Getting the shfit state for state " << currentReached->getData() << " and symbol " << reduction.symbol->toString() << std::endl;
int toState = table.getShift(currentReached->getData(), reduction.symbol)->shiftState; int toState = table.getShift(currentReached->getData(), reduction.symbol)->shiftState;
@@ -408,11 +405,14 @@ bool RNGLRParser::reducesToNull(ParseRule* rule, std::vector<Symbol*> avoidList)
} }
int RNGLRParser::getNullableIndex(ParseRule* rule) { int RNGLRParser::getNullableIndex(ParseRule* rule) {
return 1; if (reducesToNull(rule))
return 1;
else
return 0;
} }
NodeTree<Symbol*>* RNGLRParser::getNullableParts(ParseRule* rule) { NodeTree<Symbol*>* RNGLRParser::getNullableParts(ParseRule* rule) {
return new NodeTree<Symbol*>("null", nullSymbol); return getNullableParts(getNullableIndex(rule));
} }
NodeTree<Symbol*>* RNGLRParser::getNullableParts(Symbol* symbol) { NodeTree<Symbol*>* RNGLRParser::getNullableParts(Symbol* symbol) {