From 7b3cfb850d02d9d7d99b873240be7f3d572198da Mon Sep 17 00:00:00 2001 From: Jan Travnicek <Jan.Travnicek@fit.cvut.cz> Date: Tue, 11 Sep 2018 22:05:08 +0200 Subject: [PATCH] make lambda callback accept references --- alib2algo/src/grammar/properties/NullableNonterminals.h | 6 +++++- .../src/grammar/properties/ProductiveNonterminals.h | 8 +++++--- .../src/grammar/simplify/UnproductiveSymbolsRemover.h | 9 ++++++--- .../src/grammar/simplify/UnreachableSymbolsRemover.h | 8 +++++--- 4 files changed, 21 insertions(+), 10 deletions(-) diff --git a/alib2algo/src/grammar/properties/NullableNonterminals.h b/alib2algo/src/grammar/properties/NullableNonterminals.h index d0446cfa6a..5c6472de99 100644 --- a/alib2algo/src/grammar/properties/NullableNonterminals.h +++ b/alib2algo/src/grammar/properties/NullableNonterminals.h @@ -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); } } diff --git a/alib2algo/src/grammar/properties/ProductiveNonterminals.h b/alib2algo/src/grammar/properties/ProductiveNonterminals.h index b70b7077a0..f7df0a21b5 100644 --- a/alib2algo/src/grammar/properties/ProductiveNonterminals.h +++ b/alib2algo/src/grammar/properties/ProductiveNonterminals.h @@ -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 ); } } diff --git a/alib2algo/src/grammar/simplify/UnproductiveSymbolsRemover.h b/alib2algo/src/grammar/simplify/UnproductiveSymbolsRemover.h index c815ce14d8..68697b0ddf 100644 --- a/alib2algo/src/grammar/simplify/UnproductiveSymbolsRemover.h +++ b/alib2algo/src/grammar/simplify/UnproductiveSymbolsRemover.h @@ -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 ); } } diff --git a/alib2algo/src/grammar/simplify/UnreachableSymbolsRemover.h b/alib2algo/src/grammar/simplify/UnreachableSymbolsRemover.h index b7b91e19cc..24c07b71d3 100644 --- a/alib2algo/src/grammar/simplify/UnreachableSymbolsRemover.h +++ b/alib2algo/src/grammar/simplify/UnreachableSymbolsRemover.h @@ -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 ); } } -- GitLab