Fixed a typo that caused indirection operators to do the reverse on types. Also cleaned up some comments. One more test working.
This commit is contained in:
41
main.cpp
41
main.cpp
@@ -48,13 +48,13 @@ int main(int argc, char* argv[]) {
|
|||||||
}
|
}
|
||||||
std::string krakenDir = argv[0];
|
std::string krakenDir = argv[0];
|
||||||
krakenDir = strSlice(krakenDir, 0, -(std::string("kraken").length()+1));
|
krakenDir = strSlice(krakenDir, 0, -(std::string("kraken").length()+1));
|
||||||
includePaths.push_back(krakenDir + "stdlib/");
|
includePaths.push_back(krakenDir + "stdlib/"); //Add the stdlib directory that exists in the same directory as the kraken executable to the path
|
||||||
std::string programName = argv[1];
|
std::string programName = argv[1];
|
||||||
std::string grammerFileString = argv[2];
|
std::string grammerFileString = argv[2];
|
||||||
std::string outputName = argv[3];
|
std::string outputName = argv[3];
|
||||||
|
|
||||||
std::ifstream grammerInFile, compiledGrammerInFile;
|
std::ifstream grammerInFile, compiledGrammerInFile;
|
||||||
std::ofstream /*outFileC,*/ compiledGrammerOutFile;
|
std::ofstream compiledGrammerOutFile;
|
||||||
|
|
||||||
grammerInFile.open(grammerFileString);
|
grammerInFile.open(grammerFileString);
|
||||||
if (!grammerInFile.is_open()) {
|
if (!grammerInFile.is_open()) {
|
||||||
@@ -63,17 +63,9 @@ int main(int argc, char* argv[]) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
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::cout << "Problem opening compiledGrammerInFile " << grammerFileString + ".comp" << "\n";
|
||||||
//return(1);
|
|
||||||
}
|
|
||||||
/*
|
|
||||||
outFileC.open((outputName + ".c").c_str());
|
|
||||||
if (!outFileC.is_open()) {
|
|
||||||
std::cout << "Probelm opening third output file " << outputName + ".c" << "\n";
|
|
||||||
return(1);
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
//Read the input file into a string
|
//Read the input file into a string
|
||||||
std::string grammerInputFileString;
|
std::string grammerInputFileString;
|
||||||
std::string line;
|
std::string line;
|
||||||
@@ -86,8 +78,6 @@ int main(int argc, char* argv[]) {
|
|||||||
//LALRParser parser;
|
//LALRParser parser;
|
||||||
RNGLRParser parser;
|
RNGLRParser parser;
|
||||||
parser.loadGrammer(grammerInputFileString);
|
parser.loadGrammer(grammerInputFileString);
|
||||||
//std::cout << "Creating State Set from Main" << std::endl;
|
|
||||||
//std::cout << "\nState Set" << std::endl;
|
|
||||||
|
|
||||||
//Start binary stuff
|
//Start binary stuff
|
||||||
bool compGramGood = false;
|
bool compGramGood = false;
|
||||||
@@ -111,7 +101,6 @@ int main(int argc, char* argv[]) {
|
|||||||
} else {
|
} else {
|
||||||
compGramGood = true;
|
compGramGood = true;
|
||||||
std::cout << "Grammer file is up to date." << std::endl;
|
std::cout << "Grammer file is up to date." << std::endl;
|
||||||
//int tableLength = *((int*)(binaryTablePointer + 4 + sizeof(int) + gramStringLength));
|
|
||||||
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 {
|
||||||
@@ -141,43 +130,23 @@ int main(int argc, char* argv[]) {
|
|||||||
}
|
}
|
||||||
//End binary stuff
|
//End binary stuff
|
||||||
|
|
||||||
//std::cout << "finished State Set from Main" << std::endl;
|
|
||||||
//std::cout << "Doing stateSetToString from Main" << std::endl;
|
|
||||||
// std::cout << "\n\n\n\n\n\n\n\n\n\nState Set toString" << std::endl;
|
|
||||||
// std::cout << parser.stateSetToString() << std::endl;
|
|
||||||
// std::cout << "finished stateSetToString from Main" << std::endl;
|
|
||||||
// std::cout << "\n\n\n\n\n\n\n\n\n\nTable" << std::endl;
|
|
||||||
// std::cout << parser.tableToString() << std::endl;
|
|
||||||
// std::cout << "\n\n\n\n\n\n\n\n\n\nGrammer Input File" << std::endl;
|
|
||||||
// std::cout << grammerInputFileString << std::endl;
|
|
||||||
// std::cout << "\n\n\n\n\n\n\n\n\n\nGrammer toString" << std::endl;
|
|
||||||
// std::cout << parser.grammerToString() << std::endl;
|
|
||||||
//std::cout << parser.grammerToDOT() << std::endl;
|
|
||||||
|
|
||||||
//outFile << parser.grammerToDOT() << std::endl;
|
|
||||||
std::cout << "\nParsing" << std::endl;
|
std::cout << "\nParsing" << std::endl;
|
||||||
|
|
||||||
Importer importer(&parser, includePaths);
|
Importer importer(&parser, includePaths);
|
||||||
|
|
||||||
/*NodeTree<ASTData>* AST =*/
|
|
||||||
for (auto i : includePaths)
|
for (auto i : includePaths)
|
||||||
std::cout << i << std::endl;
|
std::cout << i << std::endl;
|
||||||
|
|
||||||
importer.import(programName);
|
importer.import(programName);
|
||||||
std::map<std::string, NodeTree<ASTData>*> ASTs = importer.getASTMap();
|
std::map<std::string, NodeTree<ASTData>*> ASTs = importer.getASTMap();
|
||||||
|
|
||||||
//Do optomization, etc. here.
|
//Do optimization, etc. here.
|
||||||
//None at this time, instead going straight to C in this first (more naive) version
|
//None at this time, instead going straight to C in this first (more naive) version
|
||||||
|
|
||||||
//Code generation
|
//Code generation
|
||||||
//For right now, just C
|
//For right now, just C
|
||||||
|
|
||||||
CGenerator().generateCompSet(ASTs, outputName);
|
CGenerator().generateCompSet(ASTs, outputName);
|
||||||
/*
|
|
||||||
std::string c_code = CGenerator().generate(AST);
|
|
||||||
outFileC << c_code << std::endl;
|
|
||||||
outFileC.close();
|
|
||||||
*/
|
|
||||||
return(0);
|
return(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -70,11 +70,7 @@ NodeTree<ASTData>* ASTTransformation::transform(NodeTree<Symbol>* from, NodeTree
|
|||||||
if (newNode == NULL) {
|
if (newNode == NULL) {
|
||||||
std::cout << "scope lookup error! Could not find " << lookupName << " in identifier " << std::endl;
|
std::cout << "scope lookup error! Could not find " << lookupName << " in identifier " << std::endl;
|
||||||
throw "LOOKUP ERROR: " + lookupName;
|
throw "LOOKUP ERROR: " + lookupName;
|
||||||
} else if (newNode->getDataRef()->symbol.getName() !=lookupName) {
|
|
||||||
//This happens when the lookup name denotes a member of an object, i.e. obj.foo
|
|
||||||
//The newNode points to obj, not foo.
|
|
||||||
}
|
}
|
||||||
//newNode = new NodeTree<ASTData>(name, ASTData(identifier, Symbol(concatSymbolTree(children[0]), true)));
|
|
||||||
} else if (name == "type_def") {
|
} else if (name == "type_def") {
|
||||||
//If it is an alisis of a type
|
//If it is an alisis of a type
|
||||||
std::string typeAlias;
|
std::string typeAlias;
|
||||||
@@ -93,8 +89,6 @@ NodeTree<ASTData>* ASTTransformation::transform(NodeTree<Symbol>* from, NodeTree
|
|||||||
//So we give this typedef its name without any template types and make its type template_type, and point to this from node.
|
//So we give this typedef its name without any template types and make its type template_type, and point to this from node.
|
||||||
//Then, when this template is instantiated, it will run transform on from with the types filled in.
|
//Then, when this template is instantiated, it will run transform on from with the types filled in.
|
||||||
objectType = new Type(template_type, from);
|
objectType = new Type(template_type, from);
|
||||||
// skipChildren.insert(0); //Don't try to transform the template
|
|
||||||
// skipChildren.insert(1); //Identifier lookup will be ourselves, as we just added ourselves to the scope
|
|
||||||
} else {
|
} else {
|
||||||
typeAlias = concatSymbolTree(children[0]);
|
typeAlias = concatSymbolTree(children[0]);
|
||||||
newNode = new NodeTree<ASTData>(name, ASTData(type_def, Symbol(typeAlias, true, typeAlias)));
|
newNode = new NodeTree<ASTData>(name, ASTData(type_def, Symbol(typeAlias, true, typeAlias)));
|
||||||
@@ -110,7 +104,6 @@ NodeTree<ASTData>* ASTTransformation::transform(NodeTree<Symbol>* from, NodeTree
|
|||||||
if (children[0]->getData().getName() == "template_dec")
|
if (children[0]->getData().getName() == "template_dec")
|
||||||
return newNode;
|
return newNode;
|
||||||
scope = newNode;
|
scope = newNode;
|
||||||
//return newNode;
|
|
||||||
} else if (name == "function") {
|
} else if (name == "function") {
|
||||||
std::string functionName;
|
std::string functionName;
|
||||||
//If this is a function template
|
//If this is a function template
|
||||||
@@ -451,9 +444,9 @@ NodeTree<ASTData>* ASTTransformation::doFunction(NodeTree<ASTData>* scope, std::
|
|||||||
if ((nodes.size() != 2 && lookup == "*") || lookup == "&" || lookup == "[]") {
|
if ((nodes.size() != 2 && lookup == "*") || lookup == "&" || lookup == "[]") {
|
||||||
Type* newType = oldTypes[0].clone();
|
Type* newType = oldTypes[0].clone();
|
||||||
if (lookup == "*" || lookup == "[]")
|
if (lookup == "*" || lookup == "[]")
|
||||||
newType->increaseIndirection();
|
|
||||||
else
|
|
||||||
newType->decreaseIndirection();
|
newType->decreaseIndirection();
|
||||||
|
else
|
||||||
|
newType->increaseIndirection();
|
||||||
|
|
||||||
newNode->getDataRef()->valueType = newType, std::cout << "Operator " + lookup << " is altering indirection "<< std::endl;
|
newNode->getDataRef()->valueType = newType, std::cout << "Operator " + lookup << " is altering indirection "<< std::endl;
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user