Cleaned up and added line number to error messages

This commit is contained in:
Nathan Braswell
2014-02-20 18:24:04 -05:00
parent 37cffac9cd
commit 7f902880c5
2 changed files with 17 additions and 3 deletions

View File

@@ -39,6 +39,8 @@ class RNGLRParser: public Parser {
std::vector<NodeTree<Symbol>*> getPathEdges(std::vector<NodeTree<int>*> path); std::vector<NodeTree<Symbol>*> getPathEdges(std::vector<NodeTree<int>*> path);
int findLine(int tokenNum); //Get the line number for a token, used for error reporting
std::vector<Symbol> input; std::vector<Symbol> input;
GraphStructuredStack gss; GraphStructuredStack gss;
//start node, lefthand side of the reduction, reduction length //start node, lefthand side of the reduction, reduction length

View File

@@ -85,8 +85,9 @@ NodeTree<Symbol>* RNGLRParser::parseInput(std::string inputString) {
for (int i = 0; i < input.size(); i++) { for (int i = 0; i < input.size(); i++) {
// std::cout << "Checking if frontier " << i << " is empty" << std::endl; // std::cout << "Checking if frontier " << i << " is empty" << std::endl;
if (gss.frontierIsEmpty(i)) { if (gss.frontierIsEmpty(i)) {
std::cout << "Frontier " << i << " is empty." << std::endl; //std::cout << "Frontier " << i << " is empty." << std::endl;
std::cout << "Failed on " << input[i].toString() << std::endl; std::cout << "Parsing failed on " << input[i].toString() << std::endl;
std::cout << "Problem is on line: " << findLine(i) << std::endl;
std::cout << "Nearby is:" << std::endl; std::cout << "Nearby is:" << std::endl;
const int range = 10; const int range = 10;
for (int j = (i-range >= 0 ? i-range : 0); j < (i+range < input.size() ? i+range : input.size()); j++) for (int j = (i-range >= 0 ? i-range : 0); j < (i+range < input.size() ? i+range : input.size()); j++)
@@ -118,7 +119,7 @@ NodeTree<Symbol>* RNGLRParser::parseInput(std::string inputString) {
} }
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;
} }
@@ -492,3 +493,14 @@ std::vector<NodeTree<Symbol>*> RNGLRParser::getPathEdges(std::vector<NodeTree<in
pathEdges.push_back(gss.getEdge(path[i], path[i+1])); pathEdges.push_back(gss.getEdge(path[i], path[i+1]));
return pathEdges; return pathEdges;
} }
int RNGLRParser::findLine(int tokenNum) {
int lineNo = 0;
for (int i = 0; i < tokenNum; i++) {
std::string tokenString = input[i].getValue();
for (int j = 0; j < tokenString.size(); j++)
if (tokenString[j] == '\n')
lineNo++;
}
return lineNo;
}