Added ability to add commits the Kraken grammer file. Started work on class traits and else statements.
This commit is contained in:
@@ -7,8 +7,12 @@ type = type WS "\*" | "void" | "int" | "float" | "double" | "char" | identifier
|
||||
template_inst = "<" WS type_list WS ">" ;
|
||||
type_list = type_list WS "," WS type | type ;
|
||||
|
||||
template_dec = "template" WS "<" WS identifier_list WS ">" ;
|
||||
identifier_list = identifier_list WS "," WS identifier | identifier ;
|
||||
#What does that even mean?
|
||||
#some
|
||||
#
|
||||
#
|
||||
template_dec = "template" WS "<" WS template_param_list WS ">" ;
|
||||
template_param_list = template_param_list WS "," WS identifier | identifier ;
|
||||
|
||||
import = "import" WS identifier WS ";" ;
|
||||
|
||||
|
||||
@@ -503,8 +503,10 @@ NodeTree<ASTData>* ASTTransformation::transform(NodeTree<Symbol>* from, NodeTree
|
||||
}
|
||||
|
||||
// //Set the value of this function call
|
||||
if (newNode->getDataRef()->valueType == NULL && rhs->getDataRef()->valueType)
|
||||
newNode->getDataRef()->valueType = rhs->getDataRef()->valueType;
|
||||
if (newNode->getDataRef()->valueType == NULL && rhs->getDataRef()->valueType) {
|
||||
std::cout << "The value type from doFunction was null! (for " << functionCallName << ")" << std::endl;
|
||||
newNode->getDataRef()->valueType = rhs->getDataRef()->valueType;
|
||||
}
|
||||
//else
|
||||
// newNode->getDataRef()->valueType = NULL;
|
||||
std::cout << "function call to " << functionCallName << " - " << newNode->getName() << " is now " << newNode->getDataRef()->valueType << std::endl;
|
||||
@@ -754,7 +756,7 @@ NodeTree<ASTData>* ASTTransformation::doFunction(NodeTree<ASTData>* scope, std::
|
||||
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 from " << oldTypes[0].toString() << " to " << newType->toString() << std::endl;
|
||||
} else {
|
||||
newNode->getDataRef()->valueType = function->getDataRef()->valueType, std::cout << "Some other ||" << lookup << "||" << std::endl;
|
||||
}
|
||||
|
||||
@@ -36,7 +36,7 @@ Importer::Importer(Parser* parserIn, std::vector<std::string> includePaths) {
|
||||
collapseSymbols.push_back(Symbol("if_comp_pred", false));
|
||||
collapseSymbols.push_back(Symbol("declaration_block", false));
|
||||
collapseSymbols.push_back(Symbol("type_list", false));
|
||||
collapseSymbols.push_back(Symbol("identifier_list", false));
|
||||
collapseSymbols.push_back(Symbol("template_param_list", false));
|
||||
}
|
||||
|
||||
Importer::~Importer() {
|
||||
|
||||
@@ -32,10 +32,22 @@ Symbol Parser::getOrAddSymbol(std::string symbolString, bool isTerminal) {
|
||||
void Parser::loadGrammer(std::string grammerInputString) {
|
||||
reader.setString(grammerInputString);
|
||||
|
||||
std::string currToken = reader.word();
|
||||
std::string currToken = reader.word(false); //Don't truncate so we can find the newline correctly (needed for comments)
|
||||
|
||||
while(currToken != "") {
|
||||
//Load the left of the rule
|
||||
//First, if this starts with a '#', skip this
|
||||
if (currToken.front() == '#') {
|
||||
//If this line is more than one token long, eat it
|
||||
std::cout << "Ate: " << currToken << std::endl;
|
||||
if (currToken.back() != '\n')
|
||||
std::cout << "Eating " << reader.line() << " b/c grammer comment" << std::endl;
|
||||
currToken = reader.word(false);
|
||||
continue;
|
||||
}
|
||||
if (currToken.back() == '\n' || currToken.back() == ' ' || currToken.back() == '\t')
|
||||
currToken.erase(currToken.size()-1);
|
||||
|
||||
//Load the left of the rule
|
||||
ParseRule* currentRule = new ParseRule();
|
||||
Symbol leftSide = getOrAddSymbol(currToken, false); //Left handle is never a terminal
|
||||
currentRule->setLeftHandle(leftSide);
|
||||
@@ -76,7 +88,7 @@ void Parser::loadGrammer(std::string grammerInputString) {
|
||||
|
||||
loadedGrammer.push_back(currentRule);
|
||||
//Get next token
|
||||
currToken = reader.word();
|
||||
currToken = reader.word(false);
|
||||
}
|
||||
//std::cout << "Parsed!\n";
|
||||
|
||||
|
||||
@@ -57,5 +57,11 @@ template <T> void delete(T* toDelete, int itemDestructCount) {
|
||||
}
|
||||
|
||||
template <T> void delete(T* toDelete) {
|
||||
free<T>(toDelete);
|
||||
delete<T>(toDelete, true);
|
||||
}
|
||||
|
||||
template <T> void delete(T* toDelete, bool destruct) {
|
||||
if (destruct)
|
||||
toDelete->destruct();
|
||||
free<T>(toDelete);
|
||||
}
|
||||
|
||||
@@ -5,7 +5,11 @@ typedef template<T> vector {
|
||||
T *data;
|
||||
int size;
|
||||
int available;
|
||||
vector<T> *construct() {
|
||||
bool destroyItems;
|
||||
|
||||
vector<T> *construct(bool destroyItemsIn) {
|
||||
destroyItems = destroyItemsIn;
|
||||
return construct();
|
||||
size = 0;
|
||||
available = 8;
|
||||
data = new<T>(8);
|
||||
@@ -13,8 +17,10 @@ typedef template<T> vector {
|
||||
}
|
||||
|
||||
void destruct() {
|
||||
//Destruction of contained data should depend on if the stored things are objects or primitives.
|
||||
delete<T>(data, size);
|
||||
if (destroyItems)
|
||||
delete<T>(data, size);
|
||||
else
|
||||
delete<T>(data);
|
||||
}
|
||||
|
||||
bool resize(int newSize) {
|
||||
|
||||
@@ -1,2 +1,3 @@
|
||||
1337
|
||||
Destroyed!
|
||||
|
||||
|
||||
@@ -1,8 +1,14 @@
|
||||
import io;
|
||||
import vector;
|
||||
|
||||
typedef Destructable {
|
||||
void destruct() {
|
||||
println("Destroyed!");
|
||||
}
|
||||
};
|
||||
|
||||
int main() {
|
||||
vector<int> intVec.construct();
|
||||
vector<int> intVec.construct(false);
|
||||
intVec.addBack(1);
|
||||
intVec.addBack(3);
|
||||
intVec.addBack(3);
|
||||
@@ -11,5 +17,11 @@ int main() {
|
||||
print(intVec.at(i));
|
||||
|
||||
println();
|
||||
|
||||
vector<Destructable>* desVec = new<vector<Destructable>>()->construct(true);
|
||||
Destructable testDestruct;
|
||||
desVec->addBack(testDestruct);
|
||||
delete<vector<Destructable>>(desVec);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user