Skip to content
Snippets Groups Projects
Commit ffe4e18d authored by Jan Trávníček's avatar Jan Trávníček
Browse files

add conversion from LG to EpsilonFreeCFG

parent 41c8dc33
No related branches found
No related tags found
No related merge requests found
......@@ -13,41 +13,6 @@ namespace grammar {
 
namespace simplify {
 
grammar::EpsilonFreeCFG EpsilonRemover::remove(const grammar::EpsilonFreeCFG& origGrammar)
{
return origGrammar;
}
grammar::CNF EpsilonRemover::remove(const grammar::CNF& origGrammar)
{
return origGrammar;
}
grammar::GNF EpsilonRemover::remove(const grammar::GNF& origGrammar)
{
return origGrammar;
}
grammar::LeftLG EpsilonRemover::remove(const grammar::LeftLG& origGrammar)
{
return origGrammar;
}
grammar::LeftRG EpsilonRemover::remove(const grammar::LeftRG& origGrammar)
{
return origGrammar;
}
grammar::RightLG EpsilonRemover::remove(const grammar::RightLG& origGrammar)
{
return origGrammar;
}
grammar::RightRG EpsilonRemover::remove(const grammar::RightRG& origGrammar)
{
return origGrammar;
}
void removeNullableNonterminals(grammar::EpsilonFreeCFG& grammar, const std::set<alphabet::Symbol>& nullableNonterminals, const alphabet::Symbol& lhs, const std::vector<alphabet::Symbol>& rhs, unsigned i, std::vector<alphabet::Symbol> clear) {
if(rhs.size() == i) {
if(clear.size() == 0) return;
......@@ -62,7 +27,8 @@ void removeNullableNonterminals(grammar::EpsilonFreeCFG& grammar, const std::set
}
}
 
grammar::EpsilonFreeCFG EpsilonRemover::remove( const grammar::CFG & origGrammar ) {
template<class T>
grammar::EpsilonFreeCFG removeInternal( const T & origGrammar ) {
grammar::EpsilonFreeCFG grammar(origGrammar.getInitialSymbol());
 
for( const auto & symbol : origGrammar.getNonterminalAlphabet() )
......@@ -73,7 +39,7 @@ grammar::EpsilonFreeCFG EpsilonRemover::remove( const grammar::CFG & origGrammar
 
std::set<alphabet::Symbol> nullableNonterminals = grammar::properties::NullableNonterminals::getNullableNonterminals(origGrammar);
 
for( const auto & rule : origGrammar.getRules( ) )
for( const auto & rule : origGrammar.getRawRules( ) )
for(const auto & rhs : rule.second) {
if(rhs.size() == 0) continue;
 
......@@ -86,6 +52,51 @@ grammar::EpsilonFreeCFG EpsilonRemover::remove( const grammar::CFG & origGrammar
return grammar;
}
 
grammar::EpsilonFreeCFG EpsilonRemover::remove(const grammar::CFG& origGrammar)
{
return removeInternal(origGrammar);
}
grammar::EpsilonFreeCFG EpsilonRemover::remove(const grammar::EpsilonFreeCFG& origGrammar)
{
return origGrammar;
}
grammar::CNF EpsilonRemover::remove(const grammar::CNF& origGrammar)
{
return origGrammar;
}
grammar::GNF EpsilonRemover::remove(const grammar::GNF& origGrammar)
{
return origGrammar;
}
grammar::EpsilonFreeCFG EpsilonRemover::remove(const grammar::LG& origGrammar)
{
return removeInternal(origGrammar);
}
grammar::LeftLG EpsilonRemover::remove(const grammar::LeftLG& origGrammar)
{
return origGrammar;
}
grammar::LeftRG EpsilonRemover::remove(const grammar::LeftRG& origGrammar)
{
return origGrammar;
}
grammar::RightLG EpsilonRemover::remove(const grammar::RightLG& origGrammar)
{
return origGrammar;
}
grammar::RightRG EpsilonRemover::remove(const grammar::RightRG& origGrammar)
{
return origGrammar;
}
grammar::Grammar EpsilonRemover::remove(const grammar::Grammar& grammar) {
grammar::Grammar* out = NULL;
grammar.getData().Accept((void*) &out, EpsilonRemover::EPSILON_REMOVER);
......
......@@ -17,6 +17,7 @@
#include <grammar/ContextFree/EpsilonFreeCFG.h>
#include <grammar/ContextFree/CNF.h>
#include <grammar/ContextFree/GNF.h>
#include <grammar/ContextFree/LG.h>
#include <grammar/Regular/LeftLG.h>
#include <grammar/Regular/LeftRG.h>
#include <grammar/Regular/RightLG.h>
......@@ -35,6 +36,7 @@ public:
static grammar::EpsilonFreeCFG remove( const grammar::EpsilonFreeCFG & grammar );
static grammar::GNF remove( const grammar::GNF & grammar );
static grammar::CNF remove( const grammar::CNF & grammar );
static grammar::EpsilonFreeCFG remove( const grammar::LG & grammar );
static grammar::LeftLG remove( const grammar::LeftLG & grammar );
static grammar::LeftRG remove( const grammar::LeftRG & grammar );
static grammar::RightLG remove( const grammar::RightLG & grammar );
......
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