Checking for non productive rules and loops in cfg
This commit is contained in:
parent
16115b483a
commit
0e4f4228de
3 changed files with 40 additions and 0 deletions
|
|
@ -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;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue