diff --git a/alib2algo/src/grammar/generate/CockeYoungerKasami.h b/alib2algo/src/grammar/generate/CockeYoungerKasami.h index 456618cc94c32bf6877d8789202cba8bcfa123d8..16ac57768d8041cc77673b44c2a8eb444c95753f 100644 --- a/alib2algo/src/grammar/generate/CockeYoungerKasami.h +++ b/alib2algo/src/grammar/generate/CockeYoungerKasami.h @@ -22,50 +22,50 @@ namespace generate { */ class CockeYoungerKasami { public: - template < class SymbolType > - static bool generate ( const grammar::CNF < SymbolType > & grammar, const string::LinearString < SymbolType > & string ); + template < class TerminalSymbolType, class NonterminalSymbolType > + static bool generate ( const grammar::CNF < TerminalSymbolType, NonterminalSymbolType > & grammar, const string::LinearString < TerminalSymbolType > & string ); }; -template < class SymbolType > -bool CockeYoungerKasami::generate ( const grammar::CNF < SymbolType > & grammar, const string::LinearString < SymbolType > & string ) { +template < class TerminalSymbolType, class NonterminalSymbolType > +bool CockeYoungerKasami::generate ( const grammar::CNF < TerminalSymbolType, NonterminalSymbolType > & grammar, const string::LinearString < TerminalSymbolType > & string ) { unsigned stringSize = string.getContent ( ).size ( ); if ( ( stringSize == 0 ) && grammar.getGeneratesEpsilon ( ) ) return true; - ext::vector < ext::vector < ext::set < SymbolType > > > data; + ext::vector < ext::vector < ext::set < NonterminalSymbolType > > > data; data.resize ( stringSize ); for ( unsigned i = 0; i < stringSize; i++ ) data[i].resize ( stringSize - i ); for ( unsigned i = 0; i < stringSize; i++ ) - for ( const std::pair < const SymbolType, ext::set < ext::variant < SymbolType, ext::pair < SymbolType, SymbolType > > > > rule : grammar.getRules ( ) ) { - const SymbolType & lhs = rule.first; + for ( const std::pair < const NonterminalSymbolType, ext::set < ext::variant < TerminalSymbolType, ext::pair < NonterminalSymbolType, NonterminalSymbolType > > > > rule : grammar.getRules ( ) ) { + const NonterminalSymbolType & lhs = rule.first; - for ( const ext::variant < SymbolType, ext::pair < SymbolType, SymbolType > > rhs : rule.second ) - if ( rhs.template is < SymbolType > ( ) && ( rhs.template get < SymbolType > ( ) == string.getContent ( )[i] ) ) + for ( const ext::variant < TerminalSymbolType, ext::pair < NonterminalSymbolType, NonterminalSymbolType > > rhs : rule.second ) + if ( rhs.template is < TerminalSymbolType > ( ) && ( rhs.template get < TerminalSymbolType > ( ) == string.getContent ( )[i] ) ) data[0][i].insert ( lhs ); } for ( unsigned i = 1; i < stringSize; i++ ) for ( unsigned j = 0; j < stringSize - i; j++ ) { - ext::set < SymbolType > & targetCell = data[i][j]; // Element to compute + ext::set < NonterminalSymbolType > & targetCell = data[i][j]; // Element to compute for ( unsigned k = 0; k < i; k++ ) { - const ext::set < SymbolType > & vertical = data[k][j]; - const ext::set < SymbolType > & diagonal = data[i - 1 - k][j + 1 + k]; // Sources of data + const ext::set < NonterminalSymbolType > & vertical = data[k][j]; + const ext::set < NonterminalSymbolType > & diagonal = data[i - 1 - k][j + 1 + k]; // Sources of data - for ( const SymbolType & verticalElement : vertical ) { - for ( const SymbolType & diagonalElement : diagonal ) + for ( const NonterminalSymbolType & verticalElement : vertical ) { + for ( const NonterminalSymbolType & diagonalElement : diagonal ) - for ( const std::pair < const SymbolType, ext::set < ext::variant < SymbolType, ext::pair < SymbolType, SymbolType > > > > rule : grammar.getRules ( ) ) { - const SymbolType & lhs = rule.first; + for ( const std::pair < const NonterminalSymbolType, ext::set < ext::variant < TerminalSymbolType, ext::pair < NonterminalSymbolType, NonterminalSymbolType > > > > rule : grammar.getRules ( ) ) { + const NonterminalSymbolType & lhs = rule.first; - for ( const ext::variant < SymbolType, ext::pair < SymbolType, SymbolType > > rhs : rule.second ) - if ( rhs.template is < ext::pair < SymbolType, SymbolType > > ( ) ) { - const ext::pair < SymbolType, SymbolType > rhsp = rhs.template get < ext::pair < SymbolType, SymbolType > > ( ); + for ( const ext::variant < TerminalSymbolType, ext::pair < NonterminalSymbolType, NonterminalSymbolType > > rhs : rule.second ) + if ( rhs.template is < ext::pair < NonterminalSymbolType, NonterminalSymbolType > > ( ) ) { + const ext::pair < NonterminalSymbolType, NonterminalSymbolType > rhsp = rhs.template get < ext::pair < NonterminalSymbolType, NonterminalSymbolType > > ( ); if ( ( rhsp.first == verticalElement ) && ( rhsp.second == diagonalElement ) ) targetCell.insert ( lhs ); @@ -80,8 +80,8 @@ bool CockeYoungerKasami::generate ( const grammar::CNF < SymbolType > & grammar, if ( common::GlobalData::verbose ) - for ( const ext::vector < ext::set < SymbolType > > & row : data ) { - for ( const ext::set < SymbolType > & element : row ) + for ( const ext::vector < ext::set < NonterminalSymbolType > > & row : data ) { + for ( const ext::set < NonterminalSymbolType > & element : row ) common::Streams::log << element << " "; common::Streams::log << std::endl;