Use std:cerr for errors

This commit is contained in:
Nathan Braswell
2015-03-14 02:42:07 -04:00
parent 6a311fb237
commit 7a865b82e9
4 changed files with 34 additions and 33 deletions

View File

@@ -24,8 +24,8 @@ int main(int argc, char* argv[]) {
includePaths.push_back(""); //Local includePaths.push_back(""); //Local
if (argc <= 1) { if (argc <= 1) {
std::cout << "Kraken invocation: kraken sourceFile.krak grammerFile.kgm outputName" << std::endl; std::cerr << "Kraken invocation: kraken sourceFile.krak grammerFile.kgm outputName" << std::endl;
std::cout << "Or for testing do: kraken --test [optional list of names of file (.krak .expected_results) without extentions to run]" << std::endl; std::cerr << "Or for testing do: kraken --test [optional list of names of file (.krak .expected_results) without extentions to run]" << std::endl;
return 0; return 0;
} }
@@ -73,13 +73,13 @@ int main(int argc, char* argv[]) {
grammerInFile.open(grammerFileString); grammerInFile.open(grammerFileString);
if (!grammerInFile.is_open()) { if (!grammerInFile.is_open()) {
std::cout << "Problem opening grammerInFile " << grammerFileString << "\n"; std::cerr << "Problem opening grammerInFile " << grammerFileString << "\n";
return(1); return(1);
} }
compiledGrammerInFile.open(grammerFileString + ".comp", std::ios::binary | std::ios::ate); compiledGrammerInFile.open(grammerFileString + ".comp", std::ios::binary | std::ios::ate);
if (!compiledGrammerInFile.is_open()) if (!compiledGrammerInFile.is_open())
std::cout << "Problem opening compiledGrammerInFile " << grammerFileString + ".comp" << "\n"; std::cerr << "Problem opening compiledGrammerInFile " << grammerFileString + ".comp" << "\n";
//Read the input file into a string //Read the input file into a string
std::string grammerInputFileString; std::string grammerInputFileString;
@@ -119,7 +119,7 @@ int main(int argc, char* argv[]) {
parser.importTable(binaryTablePointer + 4 + sizeof(int) + gramStringLength); //Load table starting at the table section parser.importTable(binaryTablePointer + 4 + sizeof(int) + gramStringLength); //Load table starting at the table section
} }
} else { } else {
std::cout << grammerFileString << ".comp is NOT A Valid Kraken Compiled Grammer File, aborting" << std::endl; std::cerr << grammerFileString << ".comp is NOT A Valid Kraken Compiled Grammer File, aborting" << std::endl;
return -1; return -1;
} }
delete binaryTablePointer; delete binaryTablePointer;
@@ -130,7 +130,7 @@ int main(int argc, char* argv[]) {
std::cout << "Compiled grammer file does not exist or is not up-to-date, generating table and writing it out" << std::endl; std::cout << "Compiled grammer file does not exist or is not up-to-date, generating table and writing it out" << std::endl;
compiledGrammerOutFile.open(grammerFileString + ".comp", std::ios::binary); compiledGrammerOutFile.open(grammerFileString + ".comp", std::ios::binary);
if (!compiledGrammerOutFile.is_open()) if (!compiledGrammerOutFile.is_open())
std::cout << "Could not open compiled file to write either!" << std::endl; std::cerr << "Could not open compiled file to write either!" << std::endl;
compiledGrammerOutFile.write("KRAK", sizeof(char)*4); //Let us know when we load it that this is a kraken grammer file, but don't write out compiledGrammerOutFile.write("KRAK", sizeof(char)*4); //Let us know when we load it that this is a kraken grammer file, but don't write out
compiledGrammerOutFile.flush(); // the grammer txt until we create the set, so that if we fail creating it it won't look valid compiledGrammerOutFile.flush(); // the grammer txt until we create the set, so that if we fail creating it it won't look valid
parser.createStateSet(); parser.createStateSet();

View File

@@ -366,13 +366,13 @@ NodeTree<ASTData>* ASTTransformation::transform(NodeTree<Symbol>* from, NodeTree
if (types.size()) { if (types.size()) {
newNode = functionLookup(scope, lookupName, types); newNode = functionLookup(scope, lookupName, types);
if (newNode == NULL) { if (newNode == NULL) {
std::cout << "scope lookup error! Could not find " << lookupName << " in identifier (functionLookup)" << std::endl; std::cerr << "scope lookup error! Could not find " << lookupName << " in identifier (functionLookup)" << std::endl;
throw "LOOKUP ERROR: " + lookupName; throw "LOOKUP ERROR: " + lookupName;
} }
} else { } else {
auto possibleMatches = scopeLookup(scope, lookupName); auto possibleMatches = scopeLookup(scope, lookupName);
if (!possibleMatches.size()) { if (!possibleMatches.size()) {
std::cout << "scope lookup error! Could not find " << lookupName << " in identifier (scopeLookup)" << std::endl; std::cerr << "scope lookup error! Could not find " << lookupName << " in identifier (scopeLookup)" << std::endl;
throw "LOOKUP ERROR: " + lookupName; throw "LOOKUP ERROR: " + lookupName;
} }
newNode = possibleMatches[0]; newNode = possibleMatches[0];
@@ -485,7 +485,7 @@ NodeTree<ASTData>* ASTTransformation::transform(NodeTree<Symbol>* from, NodeTree
std::string functionCallString = concatSymbolTree(children[1]); std::string functionCallString = concatSymbolTree(children[1]);
NodeTree<ASTData>* function = doFunction(scope, functionCallString, transformedChildren, templateTypeReplacements); NodeTree<ASTData>* function = doFunction(scope, functionCallString, transformedChildren, templateTypeReplacements);
if (function == NULL) { if (function == NULL) {
std::cout << "scope lookup error! Could not find " << functionCallString << " in boolean stuff " << std::endl; std::cerr << "scope lookup error! Could not find " << functionCallString << " in boolean stuff " << std::endl;
throw "LOOKUP ERROR: " + functionCallString; throw "LOOKUP ERROR: " + functionCallString;
} }
newNode = function; newNode = function;
@@ -518,13 +518,13 @@ NodeTree<ASTData>* ASTTransformation::transform(NodeTree<Symbol>* from, NodeTree
std::vector<NodeTree<ASTData>*> transformedChildren; transformedChildren.push_back(lhs); transformedChildren.push_back(rhs); std::vector<NodeTree<ASTData>*> transformedChildren; transformedChildren.push_back(lhs); transformedChildren.push_back(rhs);
newNode = doFunction(scope, functionCallName, transformedChildren, templateTypeReplacements); newNode = doFunction(scope, functionCallName, transformedChildren, templateTypeReplacements);
if (newNode == NULL) { if (newNode == NULL) {
std::cout << "scope lookup error! Could not find " << functionCallName << " in expression " << std::endl; std::cerr << "scope lookup error! Could not find " << functionCallName << " in expression " << std::endl;
throw "LOOKUP ERROR: " + functionCallName; throw "LOOKUP ERROR: " + functionCallName;
} }
// //Set the value of this function call // //Set the value of this function call
if (newNode->getDataRef()->valueType == NULL && rhs->getDataRef()->valueType) { if (newNode->getDataRef()->valueType == NULL && rhs->getDataRef()->valueType) {
std::cout << "The value type from doFunction was null! (for " << functionCallName << ")" << std::endl; std::cerr << "The value type from doFunction was null! (for " << functionCallName << ")" << std::endl;
newNode->getDataRef()->valueType = rhs->getDataRef()->valueType; newNode->getDataRef()->valueType = rhs->getDataRef()->valueType;
} }
//else //else
@@ -554,7 +554,7 @@ NodeTree<ASTData>* ASTTransformation::transform(NodeTree<Symbol>* from, NodeTree
std::vector<NodeTree<ASTData>*> transformedChildren; transformedChildren.push_back(param); std::vector<NodeTree<ASTData>*> transformedChildren; transformedChildren.push_back(param);
NodeTree<ASTData>* function = doFunction(scope, funcName, transformedChildren, templateTypeReplacements); NodeTree<ASTData>* function = doFunction(scope, funcName, transformedChildren, templateTypeReplacements);
if (function == NULL) { if (function == NULL) {
std::cout << "scope lookup error! Could not find " << funcName << " in factor " << std::endl; std::cerr << "scope lookup error! Could not find " << funcName << " in factor " << std::endl;
throw "LOOKUP ERROR: " + funcName; throw "LOOKUP ERROR: " + funcName;
} }
@@ -586,7 +586,7 @@ NodeTree<ASTData>* ASTTransformation::transform(NodeTree<Symbol>* from, NodeTree
std::string functionName = assignFuncName.substr(0,1); std::string functionName = assignFuncName.substr(0,1);
NodeTree<ASTData>* operatorCall = doFunction(scope, functionName, transformedChildren, templateTypeReplacements); NodeTree<ASTData>* operatorCall = doFunction(scope, functionName, transformedChildren, templateTypeReplacements);
if (operatorCall == NULL) { if (operatorCall == NULL) {
std::cout << "scope lookup error! Could not find " << functionName << " in assignment_statement " << std::endl; std::cerr << "scope lookup error! Could not find " << functionName << " in assignment_statement " << std::endl;
throw "LOOKUP ERROR: " + functionName; throw "LOOKUP ERROR: " + functionName;
} }
newNode->addChild(lhs); newNode->addChild(lhs);
@@ -686,13 +686,13 @@ NodeTree<ASTData>* ASTTransformation::transform(NodeTree<Symbol>* from, NodeTree
} else if (name == "bool") { } else if (name == "bool") {
newNode = new NodeTree<ASTData>(name, ASTData(value, Symbol(concatSymbolTree(children[0]), true), new Type(boolean, 0))); //Indirection of 0 for character newNode = new NodeTree<ASTData>(name, ASTData(value, Symbol(concatSymbolTree(children[0]), true), new Type(boolean, 0))); //Indirection of 0 for character
} else if (name == "AmbiguityPackOuter" || name == "AmbiguityPackInner") { } else if (name == "AmbiguityPackOuter" || name == "AmbiguityPackInner") {
std::cout << "///////////////////////////////////////////////////////////////////////////////" << std::endl; std::cerr << "///////////////////////////////////////////////////////////////////////////////" << std::endl;
std::cout << "Ambigious program when parsed by this grammer! This is a bug, please report it." << std::endl; std::cerr << "Ambigious program when parsed by this grammer! This is a bug, please report it." << std::endl;
std::cout << "///////////////////////////////////////////////////////////////////////////////" << std::endl; std::cerr << "///////////////////////////////////////////////////////////////////////////////" << std::endl;
throw "Ambigious parse!"; throw "Ambigious parse!";
} else { } else {
// Should get rid of this eventually. Right now it handles cases like sign, alpha, a comma, etc // Should get rid of this eventually. Right now it handles cases like sign, alpha, a comma, etc
std::cout << "Unhandled syntax node: " << name << std::endl; std::cerr << "Unhandled syntax node: " << name << std::endl;
return new NodeTree<ASTData>(); return new NodeTree<ASTData>();
} }
@@ -1008,10 +1008,10 @@ NodeTree<ASTData>* ASTTransformation::templateFunctionLookup(NodeTree<ASTData>*
std::cout << "Current function fits, satisfying " << currentTraitsSatisfied << " traits" << std::endl; std::cout << "Current function fits, satisfying " << currentTraitsSatisfied << " traits" << std::endl;
} }
if (!mostFittingTemplates.size()) { if (!mostFittingTemplates.size()) {
std::cout << "No template functions fit for " << lookup << "!" << std::endl; std::cerr << "No template functions fit for " << lookup << "!" << std::endl;
throw "No matching template functions"; throw "No matching template functions";
} else if (mostFittingTemplates.size() > 1) { } else if (mostFittingTemplates.size() > 1) {
std::cout << "Multiple template functions fit with equal number of traits satisfied for " << lookup << "!" << std::endl; std::cerr << "Multiple template functions fit with equal number of traits satisfied for " << lookup << "!" << std::endl;
throw "Multiple matching template functions"; throw "Multiple matching template functions";
} }
return *mostFittingTemplates.begin(); return *mostFittingTemplates.begin();
@@ -1049,7 +1049,7 @@ std::vector<NodeTree<ASTData>*> ASTTransformation::scopeLookup(NodeTree<ASTData>
} }
std::vector<NodeTree<ASTData>*> ASTTransformation::scopeLookup(NodeTree<ASTData>* scope, std::string lookup, bool includeModules, std::vector<NodeTree<ASTData>*> visited) { std::vector<NodeTree<ASTData>*> ASTTransformation::scopeLookup(NodeTree<ASTData>* scope, std::string lookup, bool includeModules, std::vector<NodeTree<ASTData>*> visited) {
std::cout << "Scp[e looking up " << lookup << std::endl; std::cout << "Scp][e looking up " << lookup << std::endl;
// Don't visit this node again when looking for the smae lookup. Note that we don't prevent coming back for the scope operator, as that should be able to come back. // Don't visit this node again when looking for the smae lookup. Note that we don't prevent coming back for the scope operator, as that should be able to come back.
visited.push_back(scope); visited.push_back(scope);
//We first check to see if it's one of the special reserved identifiers (only this, for now) and return early if it is. //We first check to see if it's one of the special reserved identifiers (only this, for now) and return early if it is.

View File

@@ -12,7 +12,8 @@ void CGenerator::generateCompSet(std::map<std::string, NodeTree<ASTData>*> ASTs,
std::string buildString = "#!/bin/sh\ncc -std=c99 "; std::string buildString = "#!/bin/sh\ncc -std=c99 ";
std::cout << "\n\n =====GENERATE PASS===== \n\n" << std::endl; std::cout << "\n\n =====GENERATE PASS===== \n\n" << std::endl;
if (mkdir(("./" + outputName).c_str(), 0755)) { if (mkdir(("./" + outputName).c_str(), 0755)) {
std::cout << "Could not make directory " << outputName << std::endl; std::cerr << "\n\n =====GENERATE PASS===== \n\n" << std::endl;
std::cerr << "Could not make directory " << outputName << std::endl;
//throw "could not make directory "; //throw "could not make directory ";
} }
@@ -27,7 +28,7 @@ void CGenerator::generateCompSet(std::map<std::string, NodeTree<ASTData>*> ASTs,
outputHFile << "#include <stdbool.h>\n#include <stdlib.h>\n#include <stdio.h>\n" << chPair.first; outputHFile << "#include <stdbool.h>\n#include <stdlib.h>\n#include <stdio.h>\n" << chPair.first;
outputCFile << "#include \"" + outputName + ".h\"\n\n" << chPair.second; outputCFile << "#include \"" + outputName + ".h\"\n\n" << chPair.second;
} else { } else {
std::cout << "Cannot open file " << outputName << ".c/h" << std::endl; std::cerr << "Cannot open file " << outputName << ".c/h" << std::endl;
} }
outputCFile.close(); outputCFile.close();
outputHFile.close(); outputHFile.close();
@@ -244,7 +245,7 @@ std::string CGenerator::generate(NodeTree<ASTData>* from, NodeTree<ASTData>* enc
case translation_unit: case translation_unit:
{ {
// Should not happen! We do this in it's own function now! // Should not happen! We do this in it's own function now!
std::cout << "Trying to normal generate a translation unit! That's a nono! (" << from->getDataRef()->toString() << ")" << std::endl; std::cerr << "Trying to normal generate a translation unit! That's a nono! (" << from->getDataRef()->toString() << ")" << std::endl;
throw "That's not gonna work"; throw "That's not gonna work";
} }
break; break;
@@ -262,7 +263,7 @@ std::string CGenerator::generate(NodeTree<ASTData>* from, NodeTree<ASTData>* enc
if (enclosingObject) if (enclosingObject)
return "this"; return "this";
else else
std::cout << "Error: this used in non-object scope" << std::endl; std::cerr << "Error: this used in non-object scope" << std::endl;
} }
//If we're in an object method, and our enclosing scope is that object, we're a member of the object and should use the this reference. //If we're in an object method, and our enclosing scope is that object, we're a member of the object and should use the this reference.
std::string preName; std::string preName;

View File

@@ -43,7 +43,7 @@ NodeTree<Symbol>* RNGLRParser::parseInput(std::string inputString) {
std::cout << "Accepted!" << std::endl; std::cout << "Accepted!" << std::endl;
return getNullableParts((*(stateSets[0]->getBasis()))[0]->getLeftSide()); return getNullableParts((*(stateSets[0]->getBasis()))[0]->getLeftSide());
} else { } else {
std::cout << "Rejected, no input (with no accepting state)" << std::endl; std::cerr << "Rejected, no input (with no accepting state)" << std::endl;
} }
return new NodeTree<Symbol>(); return new NodeTree<Symbol>();
} }
@@ -58,7 +58,7 @@ NodeTree<Symbol>* RNGLRParser::parseInput(std::string inputString) {
currentToken = lexer.next(); currentToken = lexer.next();
//std::cout << "CurrentToken is " << currentToken.toString() << std::endl; //std::cout << "CurrentToken is " << currentToken.toString() << std::endl;
if (currentToken == invalidSymbol) { if (currentToken == invalidSymbol) {
std::cout << "Invalid Symbol!" << std::endl; std::cerr << "Invalid Symbol!" << std::endl;
throw "Invalid Symbol, cannot lex"; throw "Invalid Symbol, cannot lex";
} }
input.push_back(currentToken); input.push_back(currentToken);
@@ -99,16 +99,16 @@ NodeTree<Symbol>* RNGLRParser::parseInput(std::string inputString) {
// 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 << "Parsing failed on " << input[i].toString() << std::endl; std::cerr << "Parsing failed on " << input[i].toString() << std::endl;
std::cout << "Problem is on line: " << findLine(i) << std::endl; std::cerr << "Problem is on line: " << findLine(i) << std::endl;
std::cout << "Nearby is:" << std::endl; std::cerr << "Nearby is:" << std::endl;
int range = 10; 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++)
if (j == i) if (j == i)
std::cout << "||*||*||" << input[j].toString() << "||*||*|| "; std::cerr << "||*||*||" << input[j].toString() << "||*||*|| ";
else else
std::cout << input[j].toString() << " "; std::cerr << input[j].toString() << " ";
std::cout << std::endl; std::cerr << std::endl;
range = 1; range = 1;
/* std::cout << "\n\n\nThe states in the GSS at last frontiers:" << std::endl; /* std::cout << "\n\n\nThe states in the GSS at last frontiers:" << std::endl;
for (int j = (i-range >= 0 ? i-range : 0); j < i; j++) { for (int j = (i-range >= 0 ? i-range : 0); j < i; j++) {
@@ -138,7 +138,7 @@ NodeTree<Symbol>* RNGLRParser::parseInput(std::string inputString) {
return gss.getEdge(accState, v0); return gss.getEdge(accState, v0);
} }
std::cout << "Rejected!" << std::endl; std::cerr << "Rejected!" << std::endl;
// std::cout << "GSS:\n" << gss.toString() << std::endl; // std::cout << "GSS:\n" << gss.toString() << std::endl;
return NULL; return NULL;
} }