Insert use of <error>

This commit is contained in:
kwullaer 2017-01-28 13:36:07 +01:00
parent a0ab7722b6
commit 4f55e9e9bc
1 changed files with 8 additions and 1 deletions

View File

@ -29,11 +29,16 @@ namespace pds {
for(auto& rule : cnf.grammar.rules) {
for(auto& tail_piece : rule->tail) {
if (cnf.grammar.terminals.find(tail_piece) == cnf.grammar.terminals.end() &&
cnf.grammar.variables.find(tail_piece) == cnf.grammar.variables.end())
cnf.grammar.variables.find(tail_piece) == cnf.grammar.variables.end() && tail_piece != "error")
throw InputParserException("Found '" + tail_piece + "' in rule body, which is neither a variable nor a terminal.");
}
}
for(auto& rule : cnf.grammar.rules)
if (rule->head == "error")
throw InputParserException("Found <error> terminal in a head of a rule.");
bool found_token;
for(auto& term : cnf.grammar.terminals) {
found_token = false;
@ -50,6 +55,8 @@ namespace pds {
LOG(WARNING) << "Terminal '" << term << "' is specified, but never used." << std::endl;
}
cnf.grammar.terminals.insert("error");
return cnf;
}
}