diff --git a/main.cpp b/main.cpp index 6febef3..5f1cad9 100644 --- a/main.cpp +++ b/main.cpp @@ -18,6 +18,10 @@ #include "util.h" #include "Tester.h" +#define CLEAR_SCREEN "\033[2J\033[1;1H" +#define BOLD_GREEN "\033[1m\033[32m" +#define RESET_TXT "\033[0m" + int main(int argc, char* argv[]) { std::vector includePaths; includePaths.push_back(""); //Local @@ -184,6 +188,11 @@ int main(int argc, char* argv[]) { //For right now, just C CGenerator().generateCompSet(ASTs, outputName); + + std::cout << CLEAR_SCREEN; + + std::cout << BOLD_GREEN << "SUCCESSFUL COMPILATION" << RESET_TXT << std::endl; + return(0); } diff --git a/src/RNGLRParser.cpp b/src/RNGLRParser.cpp index 869f8cf..51a7f3d 100644 --- a/src/RNGLRParser.cpp +++ b/src/RNGLRParser.cpp @@ -1,4 +1,15 @@ #include "RNGLRParser.h" +#include + +//sorry about the macros +#define RESET "\033[0m" +#define BOLDRED "\033[1m\033[31m" +#define BOLDWHITE "\033[1m\033[37m" +#define BOLDGREEN "\033[1m\033[32m" +#define BOLDYELLOW "\033[1m\033[33m" +#define BOLDBLUE "\033[1m\033[34m" +#define BOLDMAGENTA "\033[1m\033[35m" +#define BOLDCYAN "\033[1m\033[36m" RNGLRParser::RNGLRParser() { // @@ -107,25 +118,24 @@ NodeTree* RNGLRParser::parseInput(std::string inputString, std::string f //std::cout << "Frontier " << i << " is empty." << std::endl; //std::cerr << "Parsing failed on " << input[i].toString() << std::endl; //std::cerr << "Problem is on line: " << findLine(i) << std::endl; - std::cerr << filename << ":" << findLine(i) << std::endl; +// std::cerr << filename << ":" << findLine(i) << std::endl; errord = true; - std::cerr << "parse error" << std::endl; - std::cerr << "Nearby is:" << std::endl; - int range = 10; - for (int j = (i-range >= 0 ? i-range : 0); j < (i+range < input.size() ? i+range : input.size()); j++) - if (j == i) - std::cerr << "||*||*||" << input[j].toString() << "||*||*|| "; - else - std::cerr << input[j].toString() << " "; - std::cerr << std::endl; - range = 1; -/* 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++) { - std::cout << "Frontier:" << j << " (would get): " << input[j].toString() << std::endl; - printReconstructedFrontier(j); - } - std::cout << "\n\n\n\n" << std::endl; - */ break; + std::cout << BOLDMAGENTA << "parse error" << std::endl; + + std::cout << BOLDWHITE << "Error at: " << BOLDBLUE << filename << ":" << findLine(i) << std::endl; + + std::ifstream infile(filename); + std::string line; + int linecount = 0; + while(std::getline(infile,line)) + { + if(linecount == findLine(i) - 1) + std::cout << BOLDRED << line << std::endl; + linecount++; + } + std::cout << RESET << std::endl; + + break; } //Clear the vector of SPPF nodes created every step diff --git a/stdlib/io.krak b/stdlib/io.krak index f43645d..79d4e7c 100644 --- a/stdlib/io.krak +++ b/stdlib/io.krak @@ -150,3 +150,35 @@ fun write_file_binary(path: string::string, vdata: vector::vector) { } } +fun BoldRed(): void{ + print("\033[1m\033[31m"); +} + +fun BoldGreen(): void{ + print("\033[1m\033[32m"); +} + +fun BoldYellow(): void{ + print("\033[1m\033[33m"); +} + +fun BoldBlue(): void{ + print("\033[1m\033[34m"); +} + +fun BoldMagenta(): void{ + print("\033[1m\033[35m"); +} + +fun BoldCyan(): void{ + print("\033[1m\033[36m"); +} + +fun Reset(): void{ + print("\033[0m"); +} + + + + + diff --git a/stdlib/math.krak b/stdlib/math.krak index 578c091..1f4c260 100644 --- a/stdlib/math.krak +++ b/stdlib/math.krak @@ -96,6 +96,45 @@ fun sin(arg: double): double return ans; }//end sin function -//|int| NotPi = 3; -//|double| STD_PI = 4*atan(1); +fun mod(x: double, y: double): double +{ + var ans: double; + var intAns: int; + + intAns = x / y; + ans = x - intAns*y; + + return ans; +} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/stdlib/queue.krak b/stdlib/queue.krak new file mode 100644 index 0000000..ac87c02 --- /dev/null +++ b/stdlib/queue.krak @@ -0,0 +1,70 @@ +import stack +import serialize +import vector + +fun queue() : queue { + var out.construct() : queue + return out +} + +obj queue (Object, Serializable) { + var stack1 : stack::stack + var stack2 : stack::stack + + fun construct(): *queue { + stack1.construct() + stack2.construct() + return this + } + + fun copy_construct(other : *queue) { + stack1.copy_construct(&other->stack1) + stack2.copy_construct(&other->stack2) + } + + fun destruct() { + stack1.destruct() + stack2.destruct() + } + + fun operator=(other : ref queue) { + stack1 = other.stack1 + stack2 = other.stack2 + } + + fun serialize() : vector::vector { + return serialize::serialize(stack1)+serialize::serialize(stack2) + } + + fun unserialize(it : ref vector::vector, pos : int) : int { + pos = stack1.unserialize(it,pos) + pos = stack2.unserialize(it,pos) + return pos + } + + fun push(it : ref T) { + stack1.push(it) + } + + fun pop() : T { + if(stack2.empty()) { + while(!stack1.empty()) { + stack2.push(stack1.pop()) + } + } + return stack2.pop() + } + + fun clear() { + stack1.clear() + stack2.clear() + } + + fun size() : int { + return stack1.size()+stack2.size() + } + + fun empty() : bool { + return ((stack1.size()+stack2.size()) == 0) + } +} diff --git a/stdlib/util.krak b/stdlib/util.krak index e6b4962..9c6ab3b 100644 --- a/stdlib/util.krak +++ b/stdlib/util.krak @@ -35,7 +35,6 @@ obj unpack_dummy { } } - obj pair (Object, Serializable) { var first: T var second: U diff --git a/tests/test_queue.expected_results b/tests/test_queue.expected_results new file mode 100644 index 0000000..21101b1 --- /dev/null +++ b/tests/test_queue.expected_results @@ -0,0 +1,67 @@ +adding to q +pushing... +0 +pushing... +1 +pushing... +2 +pushing... +3 +pushing... +4 +pushing... +5 +pushing... +6 +pushing... +7 +pushing... +8 +pushing... +9 +adding to q2 +pushing... +9 +pushing... +8 +pushing... +7 +pushing... +6 +pushing... +5 +pushing... +4 +pushing... +3 +pushing... +2 +pushing... +1 +pushing... +0 +pop test... +0 +q is about to pop +q popped +q2 is about to pop +9 +8 +7 +6 +5 +4 +3 +2 +1 +0 +1 +2 +3 +4 +5 +6 +7 +8 +9 +done diff --git a/tests/test_queue.krak b/tests/test_queue.krak new file mode 100644 index 0000000..79cc781 --- /dev/null +++ b/tests/test_queue.krak @@ -0,0 +1,39 @@ +import queue +import io:*; + + + + +fun main() : int { + + var q.construct() : queue::queue + var q2.construct() : queue::queue + println("adding to q") + for(var i = 0; i < 10; i++;) { + defer println(i) + println("pushing...") + q.push(i) + } + + println("adding to q2") + for(var i = 9; i >= 0; i--;) { + defer println(i) + println("pushing...") + q2.push(i) + } + + println("pop test...") + println(q.pop()) + println("q is about to pop") + while(!q.empty()) { + q2.push(q.pop()) + } + println("q popped") + println("q2 is about to pop") + while(!q2.empty()) { + println(q2.pop()) + } + + println("done") + return 0 +}