From 7f902880c59e68eef613b19662de08d28d73f80f Mon Sep 17 00:00:00 2001 From: Nathan Braswell Date: Thu, 20 Feb 2014 18:24:04 -0500 Subject: [PATCH] Cleaned up and added line number to error messages --- include/RNGLRParser.h | 2 ++ src/RNGLRParser.cpp | 18 +++++++++++++++--- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/include/RNGLRParser.h b/include/RNGLRParser.h index 3e921a3..6b285e7 100644 --- a/include/RNGLRParser.h +++ b/include/RNGLRParser.h @@ -39,6 +39,8 @@ class RNGLRParser: public Parser { std::vector*> getPathEdges(std::vector*> path); + int findLine(int tokenNum); //Get the line number for a token, used for error reporting + std::vector input; GraphStructuredStack gss; //start node, lefthand side of the reduction, reduction length diff --git a/src/RNGLRParser.cpp b/src/RNGLRParser.cpp index f42f189..cbd111f 100644 --- a/src/RNGLRParser.cpp +++ b/src/RNGLRParser.cpp @@ -85,8 +85,9 @@ NodeTree* RNGLRParser::parseInput(std::string inputString) { for (int i = 0; i < input.size(); i++) { // std::cout << "Checking if frontier " << i << " is empty" << std::endl; if (gss.frontierIsEmpty(i)) { - std::cout << "Frontier " << i << " is empty." << std::endl; - std::cout << "Failed on " << input[i].toString() << std::endl; + //std::cout << "Frontier " << i << " is empty." << 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; const int range = 10; for (int j = (i-range >= 0 ? i-range : 0); j < (i+range < input.size() ? i+range : input.size()); j++) @@ -118,7 +119,7 @@ NodeTree* RNGLRParser::parseInput(std::string inputString) { } std::cout << "Rejected!" << std::endl; - std::cout << "GSS:\n" << gss.toString() << std::endl; + // std::cout << "GSS:\n" << gss.toString() << std::endl; return NULL; } @@ -492,3 +493,14 @@ std::vector*> RNGLRParser::getPathEdges(std::vector