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

make lambda callback accept references

parent a554b994
No related branches found
No related tags found
No related merge requests found
......@@ -47,11 +47,15 @@ ext::set<SymbolType> NullableNonterminals::getNullableNonterminals(const T& gram
Ni.push_back(ext::set<SymbolType>{ });
int i = 1;
 
auto testCallback = [ & ] ( const SymbolType & symb ) {
return Ni.at ( i - 1 ).count ( symb );
};
while(true) {
Ni.push_back(ext::set<SymbolType>{ });
for ( const auto & rule : rawRules ) {
for(const auto& rhs : rule.second) {
if(rhs.size() == 0 || std::all_of(rhs.begin(), rhs.end(), [Ni, i](const SymbolType& symb){return Ni.at(i-1).count(symb);})) {
if ( rhs.size ( ) == 0 || std::all_of ( rhs.begin ( ), rhs.end ( ), testCallback ) ) {
Ni.at(i).insert(rule.first);
}
}
......
......@@ -42,15 +42,17 @@ ext::set<SymbolType> ProductiveNonterminals::getProductiveNonterminals( const T
 
int i = 1;
 
auto testCallback = [ & ] ( const SymbolType & symbol ) {
return Ni.at ( i - 1 ).count ( symbol ) || grammar.getTerminalAlphabet ( ).count ( symbol );
};
// 2.
while( true ) {
Ni.push_back( Ni.at( i - 1 ) );
 
for( const auto & rule : rawRules ) {
for( const auto & rhs : rule.second ) {
if( std::all_of( rhs.begin( ), rhs.end( ), [ i, Ni, grammar ]( const SymbolType & symbol ) -> bool {
return Ni.at( i - 1 ) . count( symbol ) || grammar.getTerminalAlphabet( ). count( symbol );
} ) )
if( std::all_of( rhs.begin( ), rhs.end( ), testCallback ) )
Ni.at( i ).insert( rule.first );
}
}
......
......@@ -59,12 +59,15 @@ T UnproductiveSymbolsRemover::remove( const T & grammar ) {
auto rawRules = grammar::RawRules::getRawRules ( grammar );
 
const ext::set<SymbolType> & terminals = ret.getTerminalAlphabet( );
auto testCallback = [ & ]( const SymbolType & symbol ) {
return Nt.count( symbol ) || terminals.count( symbol );
};
for( const auto & rule : rawRules ) {
if( Nt.count( rule.first ) ) {
for( const auto & rhs : rule.second ) {
if( all_of( rhs.begin( ), rhs.end( ), [ Nt, terminals ]( const SymbolType & symbol ) {
return Nt.count( symbol ) || terminals.count( symbol );
} ) )
if( all_of( rhs.begin( ), rhs.end( ), testCallback) )
grammar::AddRawRule::addRawRule ( ret, rule.first, rhs );
}
}
......
......@@ -61,13 +61,15 @@ T UnreachableSymbolsRemover::remove( const T & grammar) {
 
auto rawRules = grammar::RawRules::getRawRules ( grammar );
 
auto testCallback = [ & ]( const SymbolType & symb ) -> bool {
return Vt.count( symb );
};
// A->\alpha: if A \in N' and \alpha in V_i*, then A->\alpha in P
for( const auto & rule : rawRules ) {
if( newNonTerminals.count( rule.first ) ) {
for( const auto& rhs : rule.second ) {
if( all_of( rhs.begin( ), rhs.end( ), [ Vt ]( SymbolType const& symb ) -> bool {
return Vt.count( symb );
} ) )
if( all_of( rhs.begin( ), rhs.end( ), testCallback ) )
grammar::AddRawRule::addRawRule ( ret, rule.first, rhs );
}
}
......
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