Fixed a pretty bad error in isNullable logic, I must have been tired. Also, edited grammer to support a[n].b, which was previously done with wrong operator precedence so that that construction was illegal. vector.krak still doesn't quite parse, but that's because of some error with if (!name) which I will fix later. Bedtime.

This commit is contained in:
Nathan Braswell
2014-07-02 01:18:27 -07:00
parent 03770028ad
commit 22fbd61360
5 changed files with 37 additions and 24 deletions

View File

@@ -179,11 +179,21 @@ bool Parser::isNullableHelper(Symbol token, std::set<Symbol> done) {
done.insert(token);
if (tokenNullable.find(token) != tokenNullable.end())
return tokenNullable[token];
//Note that we only have to check the first token on the right side, as we would only get to the other tokens if it is nullable, which is what we're checking
for (std::vector<ParseRule*>::size_type i = 0; i < loadedGrammer.size(); i++)
if (token == loadedGrammer[i]->getLeftSide())
if (isNullableHelper(loadedGrammer[i]->getRightSide()[0], done))
for (std::vector<ParseRule*>::size_type i = 0; i < loadedGrammer.size(); i++) {
if (token == loadedGrammer[i]->getLeftSide()) {
auto rightSide = loadedGrammer[i]->getRightSide();
bool ruleNullable = true;
for (int j = 0; j < rightSide.size(); j++) {
if (!isNullableHelper(rightSide[j], done)) {
ruleNullable = false;
break;
}
}
if (ruleNullable)
return true;
}
}
return false;
}