Checking for non productive rules and loops in cfg

This commit is contained in:
IlushaShurupov 2023-08-12 09:09:46 +03:00
parent b205438601
commit 616441e049
3 changed files with 40 additions and 0 deletions

View file

@ -145,5 +145,18 @@ bool CfGrammar::compile() {
rules.removeNode(rules.find(*rule.data()));
}
}
for (auto nonTerminal : mNonTerminals) {
if (!nonTerminal->val.isProductive()) {
printf("Non-terminal '%s' is not productive\n", nonTerminal->val.rules.first()->data->id.read());
return false;
}
}
Map<String, ualni> processed;
if (mNonTerminals.get(startTerminal).isLooped(processed, startTerminal)) {
printf("Note that grammar is looped.\n");
}
return true;
}

View file

@ -1,3 +1,4 @@
#include "NewPlacement.hpp"
#include "Parser.hpp"
#include "Tokenizer.hpp"