From b292bd15ae7cc2b728689ddf44a8e6d7d851717a Mon Sep 17 00:00:00 2001 From: Nathan Braswell Date: Sat, 10 Aug 2013 18:24:37 -0400 Subject: [PATCH] Now parses into parse trees! Still does not add the null-reducable trees, and there are a few ordering mistakes, but it works. --- include/NodeTree.h | 2 +- src/RNGLRParser.cpp | 18 +++++++++--------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/include/NodeTree.h b/include/NodeTree.h index 27c3a02..a57e9f6 100644 --- a/include/NodeTree.h +++ b/include/NodeTree.h @@ -220,7 +220,7 @@ std::string NodeTree::DOTGraphStringHelper() { if (children[i] != NULL) ourDOTRelation += getDOTName() + " -> " + children[i]->getDOTName() + ";\n" + children[i]->DOTGraphStringHelper(); else - ourDOTRelation += getDOTName() + " -> BAD_NULL_" + getDOTName(); + ourDOTRelation += getDOTName() + " -> BAD_NULL_" + getDOTName() + "\n"; } return(ourDOTRelation); } diff --git a/src/RNGLRParser.cpp b/src/RNGLRParser.cpp index e9a80d3..a0c24aa 100644 --- a/src/RNGLRParser.cpp +++ b/src/RNGLRParser.cpp @@ -101,10 +101,9 @@ NodeTree* RNGLRParser::parseInput(std::string inputString) { if (accState) { std::cout << "Accepted!" << std::endl; return gss.getEdge(accState, v0); - } else { - std::cout << "Rejected!" << std::endl; } + std::cout << "Rejected!" << std::endl; std::cout << "GSS:\n" << gss.toString() << std::endl; return NULL; } @@ -119,18 +118,16 @@ void RNGLRParser::reducer(int i) { for (std::vector*> >::size_type j = 0; j < paths->size(); j++) { - //Algorithm expects path in reverse order std::vector*> 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 std::vector*> pathEdges = getPathEdges(currentPath); + std::reverse(pathEdges.begin(), pathEdges.end()); //If the reduction length is 0, label as passed in is null if (reduction.length != 0) pathEdges.push_back(reduction.label); - //The end of the current path (remember reversed) - NodeTree* currentReached = currentPath[0]; + //The end of the current path + NodeTree* currentReached = currentPath[currentPath.size()-1]; 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; @@ -408,11 +405,14 @@ bool RNGLRParser::reducesToNull(ParseRule* rule, std::vector avoidList) } int RNGLRParser::getNullableIndex(ParseRule* rule) { - return 1; + if (reducesToNull(rule)) + return 1; + else + return 0; } NodeTree* RNGLRParser::getNullableParts(ParseRule* rule) { - return new NodeTree("null", nullSymbol); + return getNullableParts(getNullableIndex(rule)); } NodeTree* RNGLRParser::getNullableParts(Symbol* symbol) {