Redid lookahead in a much much saner way. Now should be a legitimate parser somewhere between LALR(1) and LR(1).

This commit is contained in:
Nathan Braswell
2013-06-26 14:27:28 -04:00
parent ee9b8b8c39
commit 6a2977d12a
5 changed files with 78 additions and 109 deletions

View File

@@ -81,7 +81,7 @@ bool State::containsRule(ParseRule* rule) {
std::string State::toString() {
std::string concat = "";
concat += "State " + intToString(number) + ":\n";
concat += "State " + intToString(number) + " with " + intToString(parents.size()) + " parents:\n";
for (std::vector<ParseRule*>::size_type j = 0; j < basis.size(); j++) {
concat += "\t" + basis[j]->toString() + "\n";
}
@@ -110,8 +110,11 @@ std::vector<State*>* State::getParents() {
}
std::vector<State*>* State::getDeepParents(int depth) {
if (depth == 1)
return &parents;
if (depth <= 0) {
std::vector<State*>* returnSelf = new std::vector<State*>();
returnSelf->push_back(this);
return returnSelf;
}
std::vector<State*>* recursiveParents = new std::vector<State*>();
std::vector<State*>* recursiveParentsToAdd;
for (std::vector<State*>::size_type i = 0; i < parents.size(); i++) {