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

adapt randomize grammar to new templating of grammars

parent 9fa2f55d
No related branches found
No related tags found
No related merge requests found
......@@ -22,91 +22,91 @@ namespace generate {
 
class RandomizeGrammar {
public:
template < class SymbolType >
static grammar::LeftRG < SymbolType > randomize ( const grammar::LeftRG < SymbolType > & gram );
template < class SymbolType >
static grammar::LeftLG < SymbolType > randomize ( const grammar::LeftLG < SymbolType > & gram );
template < class SymbolType >
static grammar::RightRG < SymbolType > randomize ( const grammar::RightRG < SymbolType > & gram );
template < class SymbolType >
static grammar::RightLG < SymbolType > randomize ( const grammar::RightLG < SymbolType > & gram );
template < class TerminalSymbolType, class NonterminalSymbolType >
static grammar::LeftRG < TerminalSymbolType, NonterminalSymbolType > randomize ( const grammar::LeftRG < TerminalSymbolType, NonterminalSymbolType > & gram );
template < class TerminalSymbolType, class NonterminalSymbolType >
static grammar::LeftLG < TerminalSymbolType, NonterminalSymbolType > randomize ( const grammar::LeftLG < TerminalSymbolType, NonterminalSymbolType > & gram );
template < class TerminalSymbolType, class NonterminalSymbolType >
static grammar::RightRG < TerminalSymbolType, NonterminalSymbolType > randomize ( const grammar::RightRG < TerminalSymbolType, NonterminalSymbolType > & gram );
template < class TerminalSymbolType, class NonterminalSymbolType >
static grammar::RightLG < TerminalSymbolType, NonterminalSymbolType > randomize ( const grammar::RightLG < TerminalSymbolType, NonterminalSymbolType > & gram );
template < class TerminalSymbolType, class NonterminalSymbolType >
static grammar::CFG < TerminalSymbolType, NonterminalSymbolType > randomize ( const grammar::CFG < TerminalSymbolType, NonterminalSymbolType > & gram );
 
};
 
template < class SymbolType >
grammar::LeftRG < SymbolType > RandomizeGrammar::randomize ( const grammar::LeftRG < SymbolType > & gram ) {
ext::map < SymbolType, SymbolType > symbolPermutationMap = common::Permutation::permutationMap ( gram.getNonterminalAlphabet ( ) );
template < class TerminalSymbolType, class NonterminalSymbolType >
grammar::LeftRG < TerminalSymbolType, NonterminalSymbolType > RandomizeGrammar::randomize ( const grammar::LeftRG < TerminalSymbolType, NonterminalSymbolType > & gram ) {
ext::map < NonterminalSymbolType, NonterminalSymbolType > symbolPermutationMap = common::Permutation::permutationMap ( gram.getNonterminalAlphabet ( ) );
 
grammar::LeftRG < SymbolType > res ( symbolPermutationMap.find ( gram.getInitialSymbol ( ) )->second );
grammar::LeftRG < TerminalSymbolType, NonterminalSymbolType > res ( symbolPermutationMap.at ( gram.getInitialSymbol ( ) ) );
 
res.setNonterminalAlphabet ( gram.getNonterminalAlphabet ( ) );
res.setTerminalAlphabet ( gram.getTerminalAlphabet ( ) );
 
for ( const std::pair < SymbolType, ext::set < ext::variant < SymbolType, ext::pair < SymbolType, SymbolType > > > > & rule : gram.getRules ( ) )
for ( const ext::variant < SymbolType, ext::pair < SymbolType, SymbolType > > & rhs : rule.second )
if ( rhs.template is < SymbolType > ( ) )
res.addRule ( symbolPermutationMap.find ( rule.first )->second, rhs );
for ( const std::pair < NonterminalSymbolType, ext::set < ext::variant < TerminalSymbolType, ext::pair < NonterminalSymbolType, TerminalSymbolType > > > > & rule : gram.getRules ( ) )
for ( const ext::variant < TerminalSymbolType, ext::pair < NonterminalSymbolType, NonterminalSymbolType > > & rhs : rule.second )
if ( rhs.template is < TerminalSymbolType > ( ) )
res.addRule ( symbolPermutationMap.at ( rule.first ), rhs );
else
res.addRule ( symbolPermutationMap.find ( rule.first )->second, ext::make_pair ( symbolPermutationMap.find ( rhs.template get < ext::pair < SymbolType, SymbolType > > ( ).first )->second, rhs.template get < ext::pair < SymbolType, SymbolType > > ( ).second ) );
res.addRule ( symbolPermutationMap.at ( rule.first ), ext::make_pair ( symbolPermutationMap.at ( rhs.template get < ext::pair < NonterminalSymbolType, TerminalSymbolType > > ( ).first ), rhs.template get < ext::pair < NonterminalSymbolType, TerminalSymbolType > > ( ).second ) );
 
return res;
}
 
template < class SymbolType >
grammar::LeftLG < SymbolType > RandomizeGrammar::randomize ( const grammar::LeftLG < SymbolType > & gram ) {
ext::map < SymbolType, SymbolType > symbolPermutationMap = common::Permutation::permutationMap ( gram.getNonterminalAlphabet ( ) );
template < class TerminalSymbolType, class NonterminalSymbolType >
grammar::LeftLG < TerminalSymbolType, NonterminalSymbolType > RandomizeGrammar::randomize ( const grammar::LeftLG < TerminalSymbolType, NonterminalSymbolType > & gram ) {
ext::map < NonterminalSymbolType, NonterminalSymbolType > symbolPermutationMap = common::Permutation::permutationMap ( gram.getNonterminalAlphabet ( ) );
 
grammar::LeftLG < SymbolType > res ( symbolPermutationMap.find ( gram.getInitialSymbol ( ) )->second );
grammar::LeftLG < TerminalSymbolType, NonterminalSymbolType > res ( symbolPermutationMap.at ( gram.getInitialSymbol ( ) ) );
 
res.setNonterminalAlphabet ( gram.getNonterminalAlphabet ( ) );
res.setTerminalAlphabet ( gram.getTerminalAlphabet ( ) );
 
for ( const std::pair < SymbolType, ext::set < ext::variant < ext::vector < SymbolType >, ext::pair < SymbolType, ext::vector < SymbolType > > > > > & rule : gram.getRules ( ) )
for ( const ext::variant < ext::vector < SymbolType >, ext::pair < SymbolType, ext::vector < SymbolType > > > & rhs : rule.second )
if ( rhs.template is < ext::vector < SymbolType > > ( ) )
res.addRule ( symbolPermutationMap.find ( rule.first )->second, rhs );
for ( const std::pair < NonterminalSymbolType, ext::set < ext::variant < ext::vector < TerminalSymbolType >, ext::pair < NonterminalSymbolType, ext::vector < TerminalSymbolType > > > > > & rule : gram.getRules ( ) )
for ( const ext::variant < ext::vector < TerminalSymbolType >, ext::pair < NonterminalSymbolType, ext::vector < TerminalSymbolType > > > & rhs : rule.second )
if ( rhs.template is < ext::vector < TerminalSymbolType > > ( ) )
res.addRule ( symbolPermutationMap.at ( rule.first ), rhs );
else
res.addRule ( symbolPermutationMap.find ( rule.first )->second, ext::make_pair ( symbolPermutationMap.find ( rhs.template get < ext::pair < SymbolType, ext::vector < SymbolType > > > ( ).first )->second, rhs.template get < ext::pair < SymbolType, ext::vector < SymbolType > > > ( ).second ) );
res.addRule ( symbolPermutationMap.at ( rule.first ), ext::make_pair ( symbolPermutationMap.at ( rhs.template get < ext::pair < NonterminalSymbolType, ext::vector < TerminalSymbolType > > > ( ).first ), rhs.template get < ext::pair < NonterminalSymbolType, ext::vector < TerminalSymbolType > > > ( ).second ) );
 
return res;
}
 
template < class SymbolType >
grammar::RightRG < SymbolType > RandomizeGrammar::randomize ( const grammar::RightRG < SymbolType > & gram ) {
ext::map < SymbolType, SymbolType > symbolPermutationMap = common::Permutation::permutationMap ( gram.getNonterminalAlphabet ( ) );
template < class TerminalSymbolType, class NonterminalSymbolType >
grammar::RightRG < TerminalSymbolType, NonterminalSymbolType > RandomizeGrammar::randomize ( const grammar::RightRG < TerminalSymbolType, NonterminalSymbolType > & gram ) {
ext::map < NonterminalSymbolType, NonterminalSymbolType > symbolPermutationMap = common::Permutation::permutationMap ( gram.getNonterminalAlphabet ( ) );
 
grammar::RightRG < SymbolType > res ( symbolPermutationMap.find ( gram.getInitialSymbol ( ) )->second );
grammar::RightRG < TerminalSymbolType, NonterminalSymbolType > res ( symbolPermutationMap.at ( gram.getInitialSymbol ( ) ) );
 
res.setNonterminalAlphabet ( gram.getNonterminalAlphabet ( ) );
res.setTerminalAlphabet ( gram.getTerminalAlphabet ( ) );
 
for ( const std::pair < SymbolType, ext::set < ext::variant < SymbolType, ext::pair < SymbolType, SymbolType > > > > & rule : gram.getRules ( ) )
for ( const ext::variant < SymbolType, ext::pair < SymbolType, SymbolType > > & rhs : rule.second )
if ( rhs.template is < SymbolType > ( ) )
res.addRule ( symbolPermutationMap.find ( rule.first )->second, rhs );
for ( const std::pair < NonterminalSymbolType, ext::set < ext::variant < TerminalSymbolType, ext::pair < TerminalSymbolType, NonterminalSymbolType > > > > & rule : gram.getRules ( ) )
for ( const ext::variant < TerminalSymbolType, ext::pair < TerminalSymbolType, NonterminalSymbolType > > & rhs : rule.second )
if ( rhs.template is < TerminalSymbolType > ( ) )
res.addRule ( symbolPermutationMap.at ( rule.first ), rhs );
else
res.addRule ( symbolPermutationMap.find ( rule.first )->second, ext::make_pair ( rhs.template get < ext::pair < SymbolType, SymbolType > > ( ).first, symbolPermutationMap.find ( rhs.template get < ext::pair < SymbolType, SymbolType > > ( ).second )->second ) );
res.addRule ( symbolPermutationMap.at ( rule.first ), ext::make_pair ( rhs.template get < ext::pair < TerminalSymbolType, NonterminalSymbolType > > ( ).first, symbolPermutationMap.at ( rhs.template get < ext::pair < TerminalSymbolType, NonterminalSymbolType > > ( ).second ) ) );
 
return res;
}
 
template < class SymbolType >
grammar::RightLG < SymbolType > RandomizeGrammar::randomize ( const grammar::RightLG < SymbolType > & gram ) {
ext::map < SymbolType, SymbolType > symbolPermutationMap = common::Permutation::permutationMap ( gram.getNonterminalAlphabet ( ) );
template < class TerminalSymbolType, class NonterminalSymbolType >
grammar::RightLG < TerminalSymbolType, NonterminalSymbolType > RandomizeGrammar::randomize ( const grammar::RightLG < TerminalSymbolType, NonterminalSymbolType > & gram ) {
ext::map < NonterminalSymbolType, NonterminalSymbolType > symbolPermutationMap = common::Permutation::permutationMap ( gram.getNonterminalAlphabet ( ) );
 
grammar::RightLG < SymbolType > res ( symbolPermutationMap.find ( gram.getInitialSymbol ( ) )->second );
grammar::RightLG < TerminalSymbolType, NonterminalSymbolType > res ( symbolPermutationMap.at ( gram.getInitialSymbol ( ) ) );
 
res.setNonterminalAlphabet ( gram.getNonterminalAlphabet ( ) );
res.setTerminalAlphabet ( gram.getTerminalAlphabet ( ) );
 
for ( const std::pair < SymbolType, ext::set < ext::variant < ext::vector < SymbolType >, ext::pair < ext::vector < SymbolType >, SymbolType > > > > & rule : gram.getRules ( ) )
for ( const ext::variant < ext::vector < SymbolType >, ext::pair < ext::vector < SymbolType >, SymbolType > > & rhs : rule.second )
if ( rhs.template is < ext::vector < SymbolType > > ( ) )
res.addRule ( symbolPermutationMap.find ( rule.first )->second, rhs );
for ( const std::pair < NonterminalSymbolType, ext::set < ext::variant < ext::vector < TerminalSymbolType >, ext::pair < ext::vector < TerminalSymbolType >, NonterminalSymbolType > > > > & rule : gram.getRules ( ) )
for ( const ext::variant < ext::vector < TerminalSymbolType >, ext::pair < ext::vector < TerminalSymbolType >, NonterminalSymbolType > > & rhs : rule.second )
if ( rhs.template is < ext::vector < TerminalSymbolType > > ( ) )
res.addRule ( symbolPermutationMap.at ( rule.first ), rhs );
else
res.addRule ( symbolPermutationMap.find ( rule.first )->second, ext::make_pair ( rhs.template get < ext::pair < ext::vector < SymbolType >, SymbolType > > ( ).first, symbolPermutationMap.find ( rhs.template get < ext::pair < ext::vector < SymbolType >, SymbolType > > ( ).second )->second ) );
res.addRule ( symbolPermutationMap.at ( rule.first ), ext::make_pair ( rhs.template get < ext::pair < ext::vector < TerminalSymbolType >, NonterminalSymbolType > > ( ).first, symbolPermutationMap.at ( rhs.template get < ext::pair < ext::vector < TerminalSymbolType >, NonterminalSymbolType > > ( ).second ) ) );
 
return res;
}
......
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