This commit is contained in:
Nathan Braswell
2015-08-29 21:46:05 -04:00
8 changed files with 286 additions and 21 deletions

View File

@@ -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<std::string> 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);
}

View File

@@ -1,4 +1,15 @@
#include "RNGLRParser.h"
#include <fstream>
//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<Symbol>* 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

View File

@@ -150,3 +150,35 @@ fun write_file_binary(path: string::string, vdata: vector::vector<char>) {
}
}
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");
}

View File

@@ -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;
}

70
stdlib/queue.krak Normal file
View File

@@ -0,0 +1,70 @@
import stack
import serialize
import vector
fun queue<T>() : queue<T> {
var out.construct() : queue<T>
return out
}
obj queue<T> (Object, Serializable) {
var stack1 : stack::stack<T>
var stack2 : stack::stack<T>
fun construct(): *queue<T> {
stack1.construct()
stack2.construct()
return this
}
fun copy_construct(other : *queue<T>) {
stack1.copy_construct(&other->stack1)
stack2.copy_construct(&other->stack2)
}
fun destruct() {
stack1.destruct()
stack2.destruct()
}
fun operator=(other : ref queue<T>) {
stack1 = other.stack1
stack2 = other.stack2
}
fun serialize() : vector::vector<char> {
return serialize::serialize(stack1)+serialize::serialize(stack2)
}
fun unserialize(it : ref vector::vector<char>, 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)
}
}

View File

@@ -35,7 +35,6 @@ obj unpack_dummy<T,U> {
}
}
obj pair<T,U> (Object, Serializable) {
var first: T
var second: U

View File

@@ -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

39
tests/test_queue.krak Normal file
View File

@@ -0,0 +1,39 @@
import queue
import io:*;
fun main() : int {
var q.construct() : queue::queue<int>
var q2.construct() : queue::queue<int>
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
}