Added trivial standard library and search paths.
This commit is contained in:
@@ -12,3 +12,5 @@ include_directories( ${MY_INCLUDES} )
|
||||
|
||||
add_executable(kraken ${MY_SOURCES})
|
||||
|
||||
file(COPY stdlib DESTINATION .)
|
||||
|
||||
|
||||
@@ -16,11 +16,12 @@
|
||||
|
||||
class Importer {
|
||||
public:
|
||||
Importer(Parser* parserIn);
|
||||
Importer(Parser* parserIn, std::vector<std::string> includePaths);
|
||||
~Importer();
|
||||
NodeTree<ASTData>* import(std::string fileName);
|
||||
std::map<std::string, NodeTree<ASTData>*> getASTMap();
|
||||
private:
|
||||
std::vector<std::string> includePaths;
|
||||
Parser* parser;
|
||||
std::vector<Symbol> removeSymbols;
|
||||
std::vector<Symbol> collapseSymbols;
|
||||
|
||||
12
main.cpp
12
main.cpp
@@ -18,6 +18,9 @@
|
||||
#include "util.h"
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
std::vector<std::string> includePaths;
|
||||
includePaths.push_back(""); //Local
|
||||
|
||||
if (argc == 2 && std::string(argv[1]) == "--test") {
|
||||
StringReader::test();
|
||||
RegEx::test();
|
||||
@@ -25,7 +28,9 @@ int main(int argc, char* argv[]) {
|
||||
//std::cout << strSlice("123", 0, -1) << std::endl;
|
||||
return 0;
|
||||
}
|
||||
|
||||
std::string krakenDir = argv[0];
|
||||
krakenDir = strSlice(krakenDir, 0, -(std::string("kraken").length()+1));
|
||||
includePaths.push_back(krakenDir + "stdlib/");
|
||||
std::string programName = argv[1];
|
||||
std::string grammerFileString = argv[2];
|
||||
std::string outputName = argv[3];
|
||||
@@ -134,9 +139,12 @@ int main(int argc, char* argv[]) {
|
||||
//outFile << parser.grammerToDOT() << std::endl;
|
||||
std::cout << "\nParsing" << std::endl;
|
||||
|
||||
Importer importer(&parser);
|
||||
Importer importer(&parser, includePaths);
|
||||
|
||||
/*NodeTree<ASTData>* AST =*/
|
||||
for (auto i : includePaths)
|
||||
std::cout << i << std::endl;
|
||||
|
||||
importer.import(programName);
|
||||
std::map<std::string, NodeTree<ASTData>*> ASTs = importer.getASTMap();
|
||||
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
#include "Importer.h"
|
||||
|
||||
Importer::Importer(Parser* parserIn) {
|
||||
Importer::Importer(Parser* parserIn, std::vector<std::string> includePaths) {
|
||||
//constructor
|
||||
parser = parserIn;
|
||||
this->includePaths = includePaths;
|
||||
|
||||
removeSymbols.push_back(Symbol("WS", false));
|
||||
removeSymbols.push_back(Symbol("\\(", true));
|
||||
@@ -47,7 +48,11 @@ NodeTree<ASTData>* Importer::import(std::string fileName) {
|
||||
|
||||
std::string outputName = fileName + "out";
|
||||
|
||||
programInFile.open(fileName);
|
||||
for (auto i : includePaths) {
|
||||
programInFile.open(i+fileName);
|
||||
if (programInFile.is_open())
|
||||
break;
|
||||
}
|
||||
if (!programInFile.is_open()) {
|
||||
std::cout << "Problem opening programInFile " << fileName << "\n";
|
||||
return NULL;
|
||||
|
||||
30
stdlib/io.krak
Normal file
30
stdlib/io.krak
Normal file
@@ -0,0 +1,30 @@
|
||||
__if_comp__ __C__ __simple_passthrough__ """
|
||||
#include <stdio.h>
|
||||
"""
|
||||
|
||||
void print(char* toPrint) {
|
||||
__if_comp__ __C__ {
|
||||
__simple_passthrough__ """
|
||||
printf(toPrint);
|
||||
"""
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
void print(int toPrint) {
|
||||
__if_comp__ __C__ {
|
||||
__simple_passthrough__ """
|
||||
printf("%d", toPrint);
|
||||
"""
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
void print(float toPrint) {
|
||||
__if_comp__ __C__ {
|
||||
__simple_passthrough__ """
|
||||
printf("%f", toPrint);
|
||||
"""
|
||||
}
|
||||
return;
|
||||
}
|
||||
9
stdlib/math.krak
Normal file
9
stdlib/math.krak
Normal file
@@ -0,0 +1,9 @@
|
||||
|
||||
int NotPi = 3;
|
||||
float Pi = 3.141592654;
|
||||
|
||||
int fibanacci(int num) {
|
||||
if (num < 2)
|
||||
return 1;
|
||||
return fibanacci(num-1) + fibanacci(num-2);
|
||||
}
|
||||
Reference in New Issue
Block a user