Fixed some bugs in Parser::firstSet and added a bit of caching. It still doesn't work quite right, though, there's some problem with nullable left recursion. However, it's better than it was, and I need to go to bed. More work later.

This commit is contained in:
Nathan Braswell
2014-06-30 01:57:50 -07:00
parent 12f57f8ce8
commit 03770028ad
19 changed files with 273 additions and 78 deletions

View File

@@ -2,6 +2,10 @@ __if_comp__ __C__ __simple_passthrough__ """
#include <stdio.h>
"""
void println() {
print("\n");
}
void print(char* toPrint) {
__if_comp__ __C__ {
__simple_passthrough__ """
@@ -13,7 +17,7 @@ void print(char* toPrint) {
void println(char* toPrint) {
print(toPrint);
print("\n");
println();
}
void print(int toPrint) {
@@ -27,7 +31,7 @@ void print(int toPrint) {
void println(int toPrint) {
print(toPrint);
print("\n");
println();
}
void print(float toPrint) {
@@ -41,6 +45,6 @@ void print(float toPrint) {
void println(float toPrint) {
print(toPrint);
print("\n");
println();
}

View File

@@ -50,6 +50,12 @@ template <T> T* new() {
return new<T>(1);
}
template <T> void delete(T* toDelete, int itemDestructCount) {
for (int i = 0; i < itemDestructCount; i++)
toDelete[i].destruct();
delete(toDelete);
}
template <T> void delete(T* toDelete) {
free<T>(toDelete);
}

12
stdlib/util.krak Normal file
View File

@@ -0,0 +1,12 @@
template<T> T greater(T a, T b) {
if (a > b)
return a;
return b;
}
template<T> T lesser(T a, T b) {
if (a > b)
return b;
return a;
}

52
stdlib/vector.krak Normal file
View File

@@ -0,0 +1,52 @@
import mem;
import util;
typedef template<T> vector {
T *data;
int size;
int available;
vector<T> *construct() {
size = 0;
available = 8;
data = new<T>(8);
return this;
}
void destruct() {
//Destruction of contained data should depend on if the stored things are objects or primitives.
delete<T>(data, size);
}
bool resize(int newSize) {
T* newData = new<T>(newSize);
if (!newData)
return false;
for (int i = 0; i < lesser(size, newSize); i++;)
newData[i] = data[i];
delete<T>(data, 0);
return true;
}
T at(int index) {
return get(index);
}
T get(int index) {
if (index < 0 || index >= size)
return null;
return data[index];
}
void set(int index, T dataIn) {
if (index < 0 || index => size)
return;
data[index] = dataIn;
}
void addEnd(T dataIn) {
if (size < available)
size++;
else
resize(size*2);
data[size-1];
}
};