Skip to content
Snippets Groups Projects
Commit 95c97972 authored by Tomáš Pecka's avatar Tomáš Pecka
Browse files

algo: fa2rg: fa2rrg: Use epsilon generation sign

parent eb00bf77
No related branches found
No related tags found
No related merge requests found
......@@ -45,47 +45,9 @@ grammar::RightRG FAtoRRGConverter::convert(const automaton::NFA& automaton)
 
// step 4
if(automaton.getFinalStates().count(*automaton.getInitialStates().begin()))
{
if( ! this->isSymbolOnAnyRightHandSide(grammar.getInitialSymbol(), grammar)) // 4a
{
grammar.setGeneratesEpsilon(true);
}
else // 4b
{
alphabet::Symbol newStart = alphabet::createUniqueSymbol(grammar.getInitialSymbol(), grammar.getTerminalAlphabet(), grammar.getNonterminalAlphabet());
grammar.addNonterminalSymbol(newStart);
for(const auto& rule : grammar.getRules())
for(const auto& rightSide : rule.second)
if(rule.first == grammar.getInitialSymbol())
grammar.addRule(newStart, rightSide);
grammar.setInitialSymbol(newStart);
grammar.setGeneratesEpsilon(true);
}
}
grammar.setGeneratesEpsilon(true); // okay this feature breaks algorithm but simplifies the code actually :))
 
return grammar;
}
 
bool FAtoRRGConverter::isSymbolOnAnyRightHandSide(const alphabet::Symbol& symbol, const grammar::RightRG& grammar) const
{
for(const auto& rule : grammar.getRules())
for(const auto& rightSide : rule.second)
if(rightSide.is<std::pair<alphabet::Symbol, alphabet::Symbol>>( ))
{
const std::pair<alphabet::Symbol, alphabet::Symbol>& rhs = rightSide.get<std::pair<alphabet::Symbol, alphabet::Symbol>>();
if(rhs.first == symbol || rhs.second == symbol)
return true;
}
else
{
const alphabet::Symbol& rhs = rightSide.get<alphabet::Symbol>();
if(rhs == symbol)
return true;
}
return false;
}
} /* namespace fa2rg */
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment