diff --git a/alib2algo/src/rte/convert/ToPostfixPushdownAutomatonGlushkovV3.cpp b/alib2algo/src/rte/convert/ToPostfixPushdownAutomatonGlushkovV3.cpp new file mode 100644 index 0000000000000000000000000000000000000000..6dcaeb5deb957c238c7f850d9ebb75933067bb30 --- /dev/null +++ b/alib2algo/src/rte/convert/ToPostfixPushdownAutomatonGlushkovV3.cpp @@ -0,0 +1,161 @@ +/* + * ToPostfixPushdownAutomatonGlushkovV3.cpp + * + * Created on: 26. 7. 2017 + * Author: Tomas Pecka + */ + +#include "ToPostfixPushdownAutomatonGlushkovV3.h" + +#include "alphabet/BottomOfTheStackSymbol.h" +#include "alphabet/EndSymbol.h" + +#include <automaton/Automaton.h> + +#include "global/GlobalData.h" + +#include "../glushkov/GlushkovFollowV3.h" +#include "../glushkov/GlushkovIndexate.h" +#include "../glushkov/GlushkovFirst.h" +#include <registration/AlgoRegistration.hpp> + +namespace rte { + +namespace convert { + +automaton::Automaton ToPostfixPushdownAutomatonGlushkovV3::convert ( const rte::RTE & rte ) { + return dispatch ( rte.getData ( ) ); +} + +/* +std::vector < DefaultSymbolType > phi ( const std::vector < std::ranked_symbol < > > & follow ) { + return std::transform < DefaultSymbolType > ( follow, []( const std::ranked_symbol < > & symbol ) { return DefaultSymbolType ( alphabet::RankedSymbol < > ( symbol ) ); } ); +} + +*/ + +template < class SymbolType, class RankType > +bool ToPostfixPushdownAutomatonGlushkovV3::isSubstSymbolPresent ( const std::set < std::ranked_symbol < SymbolType, RankType > > & container, const TAlphabet < SymbolType, RankType > & substAlphabet ) { + std::vector < std::ranked_symbol < > > intersection; + std::set_intersection ( container.begin ( ), container.end ( ), substAlphabet.begin ( ), substAlphabet.end ( ), std::back_inserter ( intersection ) ); + return intersection.size ( ) > 0; +} + +template < class SymbolType, class RankType > +automaton::NPDA < SymbolType, DefaultEpsilonType, std::variant < alphabet::BottomOfTheStackSymbol, std::set < std::ranked_symbol < SymbolType, RankType > > >, DefaultStateType > +ToPostfixPushdownAutomatonGlushkovV3::convert ( const rte::FormalRTE < > & rte ) { + + // step 1; index RTE + rte::FormalRTE < > indexedRTE = rte::GlushkovIndexate::index ( rte ); + + // step 2; compute: + // - first set + const std::set < std::ranked_symbol < > > firstSet = rte::GlushkovFirst::first ( indexedRTE ); + + // - follow set for every element of (non-indexed) RTE alphabet element + std::map < std::ranked_symbol < >, std::set < GlushkovFollowV3::TFollowTuple < SymbolType, RankType > > > followSet; + + for ( const std::ranked_symbol < > & symbol : indexedRTE.getAlphabet ( ) ) + followSet.insert ( std::make_pair ( symbol, rte::GlushkovFollowV3::follow ( indexedRTE, symbol ) ) ); + + /* check for exceptions -> there must be NO substitution symbol in first set */ + if ( isSubstSymbolPresent ( firstSet, rte.getSubstitutionAlphabet ( ) ) ) + throw exception::CommonException ( "GlushkovRTE: Substitution symbol appeared in the first set" ); + /* check end */ + + /* check for exceptions -> there must be NO substitution symbol in follow sets */ + for ( const std::pair < const std::ranked_symbol < SymbolType, RankType >, std::set < GlushkovFollowV3::TFollowTuple < SymbolType, RankType > > > & kv : followSet ) + for ( const GlushkovFollowV3::TFollowTuple < SymbolType, RankType > & followTuple : kv.second ) // TFollowTuple = vector < set < ranked_symbol > > + for ( const std::set < std::ranked_symbol < SymbolType, RankType > > & followTupleElem : followTuple ) + if ( isSubstSymbolPresent ( followTupleElem, rte.getSubstitutionAlphabet ( ) ) ) + throw exception::CommonException ( "GlushkovRTE: Substitution symbol appeared in a follow set" ); + /* check end */ + + // step 3; create PDA (w/o transitions yet) and initialize input alphabet = (non-indexed) RTE alphabet and END symbol + DefaultStateType q = DefaultStateType ( 'q' ); + DefaultStateType f = DefaultStateType ( 'f' ); + + auto bots = std::variant < alphabet::BottomOfTheStackSymbol, std::set < std::ranked_symbol < SymbolType, RankType > > >::template from < alphabet::BottomOfTheStackSymbol > ( ); + automaton::NPDA < SymbolType, DefaultEpsilonType, std::variant < alphabet::BottomOfTheStackSymbol, std::set < std::ranked_symbol < SymbolType, RankType > > >, DefaultStateType > automaton ( q, bots ); + + automaton.addState ( f ); + automaton.addFinalState ( f ); + + for ( const std::ranked_symbol < > & symbol : rte.getAlphabet ( ) ) + automaton.addInputSymbol ( symbol.getSymbol ( ) ); + + automaton.addInputSymbol ( alphabet::EndSymbol::instance < DefaultSymbolType > ( ) ); + + // step 4; create pushdown store alphabet; it consists of elements of indexed RTE alphabet and BotS symbol + /* + for ( const std::ranked_symbol < > & symb : indexedRTE.getAlphabet ( ) ) + automaton.addPushdownStoreSymbol ( DefaultSymbolType ( alphabet::RankedSymbol < > ( symb ) ) ); + */ + + /* DEBUG */ + if ( common::GlobalData::verbose ) { + std::cerr << "RTE:" << std::endl; + + for ( const auto & symbol : indexedRTE.getAlphabet ( ) ) + std::cerr << "\t" << symbol << std::endl; + + std::cerr << std::endl; + + std::cerr << "First(RTE):" << std::endl; + + for ( const auto & symbol : firstSet ) + std::cerr << "\t" << symbol << std::endl; + + std::cerr << std::endl; + + for ( const auto & kv : followSet ) { + std::cerr << "Follow(RTE, " << kv.first << "):" << std::endl; + + if ( kv.second.empty ( ) ) + std::cerr << "\t" << "{}" << std::endl; + + for ( const auto & follow : kv.second ) { + for ( const auto & symbol : follow ) + std::cerr << "\t" << symbol << std::endl; + + std::cerr << std::endl; + } + + std::cerr << std::endl; + } + } + /* DEBUG END */ + + /* + for ( const std::ranked_symbol < > & symb : indexedRTE.getAlphabet ( ) ) { + if ( symb.getRank ( ) == primitive::Unsigned ( 0 ) ) + automaton.addTransition ( q, rte::GlushkovIndexate::getSymbolFromGlushkovPair ( symb ).getSymbol ( ), { }, q, { DefaultSymbolType ( alphabet::RankedSymbol < > ( symb ) ) } ); + else; + //for ( const std::vector < std::ranked_symbol < > > & follow : followSet[symb] ) { + //std::vector < DefaultSymbolType > fstring = phi ( follow ); + //std::reverse ( fstring.begin ( ), fstring.end ( ) ); + //automaton.addTransition ( q, rte::GlushkovIndexate::getSymbolFromGlushkovPair ( symb ).getSymbol ( ), fstring, q, { DefaultSymbolType ( alphabet::RankedSymbol < > ( symb ) ) } ); + //} + + } + */ + + /* + for ( const std::ranked_symbol < > & symb : firstSet ) { + std::vector < DefaultSymbolType > pop; + pop.push_back ( DefaultSymbolType ( alphabet::RankedSymbol < > ( symb ) ) ); + pop.push_back ( alphabet::BottomOfTheStackSymbol::instance < DefaultSymbolType > ( ) ); + automaton.addTransition ( q, alphabet::EndSymbol::instance < DefaultSymbolType > ( ), pop, f, { } ); + } + */ + + return automaton; +} + +auto ToAutomatonGlushkovFormalRegExpV3 = registration::OverloadRegister < ToPostfixPushdownAutomatonGlushkovV3, + automaton::NPDA < DefaultSymbolType, DefaultEpsilonType, std::variant < alphabet::BottomOfTheStackSymbol, std::set < std::ranked_symbol < alib::Object, primitive::Unsigned > > >, DefaultStateType >, + rte::FormalRTE < > > ( ToPostfixPushdownAutomatonGlushkovV3::convert ); + +} /* namespace convert */ + +} /* namespace rte */ diff --git a/alib2algo/src/rte/convert/ToPostfixPushdownAutomatonGlushkovV3.h b/alib2algo/src/rte/convert/ToPostfixPushdownAutomatonGlushkovV3.h new file mode 100644 index 0000000000000000000000000000000000000000..2be717f8d4749118eb3c44dbb026434ace9c1149 --- /dev/null +++ b/alib2algo/src/rte/convert/ToPostfixPushdownAutomatonGlushkovV3.h @@ -0,0 +1,56 @@ +/* + * ToPostfixPushdownAutomatonGlushkovV3.h + * + * Created on: 26. 7. 2017 + * Author: Tomas Pecka + */ + +#ifndef TO_POSTFIX_PUSHDOWN_AUTOMATON_GLUSHKOV_V3_H_ +#define TO_POSTFIX_PUSHDOWN_AUTOMATON_GLUSHKOV_V3_H_ + +#include <core/multipleDispatch.hpp> +#include <map> + +#include <automaton/PDA/NPDA.h> + +#include <rte/RTE.h> +#include <rte/formal/FormalRTE.h> + +// #include <rte/unbounded/UnboundedRegExp.h> + +namespace rte { + +namespace convert { + +/** + * Converts regular tree expression to real-time height-deterministic pda + * Source: Master Thesis, Pecka Tomas, CTU FIT, 2016, chapter 4.2 + */ +class ToPostfixPushdownAutomatonGlushkovV3 : public std::SingleDispatch < ToPostfixPushdownAutomatonGlushkovV3, automaton::Automaton, const rte::RTEBase & > { +private: + // -------------------------------------------------------------------- + + template < class SymbolType, class RankType > + using TAlphabet = std::set < std::ranked_symbol < SymbolType, RankType > >; + + // -------------------------------------------------------------------- + + template < class SymbolType, class RankType > + static bool isSubstSymbolPresent ( const std::set < std::ranked_symbol < SymbolType, RankType > > & container, const TAlphabet < SymbolType, RankType > & substAlphabet ); +public: + /** + * Performs conversion. + * @param re Original regular tree expression. + * @return rhNPDA equivalent to original regular expression. + */ + static automaton::Automaton convert ( const rte::RTE & rte ); + + template < class SymbolType, class RankType > + static automaton::NPDA < SymbolType, DefaultEpsilonType, std::variant < alphabet::BottomOfTheStackSymbol, std::set < std::ranked_symbol < SymbolType, RankType > > >, DefaultStateType > convert ( const rte::FormalRTE < > & rte ); +}; + +} /* namespace convert */ + +} /* namespace rte */ + +#endif /* TO_POSTFIX_PUSHDOWN_AUTOMATON_GLUSHKOV_V3_H_ */ diff --git a/alib2algo/src/rte/glushkov/GlushkovFollowV3.h b/alib2algo/src/rte/glushkov/GlushkovFollowV3.h new file mode 100644 index 0000000000000000000000000000000000000000..052e2453951eedf39da641fd240630fbdccbf318 --- /dev/null +++ b/alib2algo/src/rte/glushkov/GlushkovFollowV3.h @@ -0,0 +1,218 @@ +/* + * GlushkovFollowV3.h + * + * Created on: 26. 7. 2017 + * Author: Tomas Pecka + */ + +#ifndef RTE_GLUSHKOV_FOLLOW_V3_H_ +#define RTE_GLUSHKOV_FOLLOW_V3_H_ + +#include <map> +#include <set> +#include <vector> + +#include <rte/formal/FormalRTE.h> +#include <rte/formal/FormalRTEElements.h> + +#include <alphabet/RankedSymbol.h> + +#include "GlushkovFirst.h" +#include "GlushkovPos.h" +#include <iterator> +#include <vector> + +namespace rte { + +class GlushkovFollowV3 { + + // -------------------------------------------------------------------- +public: + + template < class SymbolType, class RankType > + using TFollowTuple = std::vector < std::set < std::ranked_symbol < SymbolType, RankType > > >; + + template < class SymbolType, class RankType > + using TAlphabet = std::set < std::ranked_symbol < SymbolType, RankType > >; + +private: + template < class SymbolType, class RankType > + using TSubstMap = std::map < std::ranked_symbol < SymbolType, RankType >, std::set < std::ranked_symbol < SymbolType, RankType > > >; + + // -------------------------------------------------------------------- + + template < class SymbolType, class RankType > + static std::set < TFollowTuple < SymbolType, RankType > > replaceConstants ( const TAlphabet < SymbolType, RankType > & alphabetK, const std::vector < std::ranked_symbol < SymbolType, RankType > > & follow, const TSubstMap < SymbolType, RankType > & subMap2 ); + + template < class SymbolType, class RankType > + static void preprocessSubMap ( const TAlphabet < SymbolType, RankType > & alphabetK, TSubstMap < SymbolType, RankType > & subMap ); + + template < class T > + static std::vector < std::vector < T > > cartesian ( const std::vector < std::vector < T > > & input ); + + template < class T > + static void cartesian_rec ( const std::vector < std::vector < T > > & input, std::vector < std::vector < T > > & ret, std::vector < T > & current, size_t depth ); + +public: + /** + * @param re rte to probe + * @param symbol FormalRTESymbol for which we need the follow(), i.e., Follow(RTE, symbol) + * @return all symbols that can follow specific symbol in word + */ + template < class SymbolType, class RankType > + static std::set < TFollowTuple < SymbolType, RankType > > follow ( const rte::FormalRTE < SymbolType, RankType > & re, const std::ranked_symbol < SymbolType, RankType > & symbol ); + + template < class SymbolType, class RankType > + class Formal { + public: + static std::set < TFollowTuple < SymbolType, RankType > > visit ( const rte::FormalRTEElement < SymbolType, RankType > & node, const std::ranked_symbol < SymbolType, RankType > & symbol, const TAlphabet < SymbolType, RankType > & alphabetK, TSubstMap < SymbolType, RankType > & subM ); + static std::set < TFollowTuple < SymbolType, RankType > > visit ( const rte::FormalRTEAlternation < SymbolType, RankType > & node, const std::ranked_symbol < SymbolType, RankType > & symbol, const TAlphabet < SymbolType, RankType > & alphabetK, TSubstMap < SymbolType, RankType > & subM ); + static std::set < TFollowTuple < SymbolType, RankType > > visit ( const rte::FormalRTESubstitution < SymbolType, RankType > & node, const std::ranked_symbol < SymbolType, RankType > & symbol, const TAlphabet < SymbolType, RankType > & alphabetK, TSubstMap < SymbolType, RankType > & subM ); + static std::set < TFollowTuple < SymbolType, RankType > > visit ( const rte::FormalRTEIteration < SymbolType, RankType > & node, const std::ranked_symbol < SymbolType, RankType > & symbol, const TAlphabet < SymbolType, RankType > & alphabetK, TSubstMap < SymbolType, RankType > & subM ); + static std::set < TFollowTuple < SymbolType, RankType > > visit ( const rte::FormalRTESymbolAlphabet < SymbolType, RankType > & node, const std::ranked_symbol < SymbolType, RankType > & symbol, const TAlphabet < SymbolType, RankType > & alphabetK, TSubstMap < SymbolType, RankType > & subM ); + static std::set < TFollowTuple < SymbolType, RankType > > visit ( const rte::FormalRTESymbolSubst < SymbolType, RankType > & node, const std::ranked_symbol < SymbolType, RankType > & symbol, const TAlphabet < SymbolType, RankType > & alphabetK, TSubstMap < SymbolType, RankType > & subM ); + static std::set < TFollowTuple < SymbolType, RankType > > visit ( const rte::FormalRTEEmpty < SymbolType, RankType > & node, const std::ranked_symbol < SymbolType, RankType > & symbol, const TAlphabet < SymbolType, RankType > & alphabetK, TSubstMap < SymbolType, RankType > & subM ); + }; + +}; + +template < class SymbolType, class RankType > +std::set < GlushkovFollowV3::TFollowTuple < SymbolType, RankType > > GlushkovFollowV3::follow ( const rte::FormalRTE < SymbolType, RankType > & rte, const std::ranked_symbol < SymbolType, RankType > & symbol ) { + TSubstMap < SymbolType, RankType > subMap; + + /* Init substitution map, ie \forall a \in K: sub[a] = \emptyset */ + for ( const std::ranked_symbol < SymbolType, RankType > & ssymb : rte.getSubstitutionAlphabet ( ) ) + subMap.insert ( std::make_pair ( ssymb, TAlphabet < SymbolType, RankType > { } ) ); + + /* recursively compute follow */ + return rte.getRTE ( ).getStructure ( ).template accept < std::set < TFollowTuple < SymbolType, RankType > >, GlushkovFollowV3::Formal < SymbolType, RankType > > ( symbol, rte.getSubstitutionAlphabet ( ), subMap ); +} + +// ----------------------------------------------------------------------------- + +/** + * Preprocessing: + * - Let k1, k2 be elements of alphabet K. + * - If k1 is an element of substMap[k2], then copy content of substMap[k1] into substMap[k2] + */ +template < class SymbolType, class RankType > +void GlushkovFollowV3::preprocessSubMap ( const TAlphabet < SymbolType, RankType > & alphabetK, TSubstMap < SymbolType, RankType > & subMap ) { + for ( bool change = true; change; change = false ) + for ( std::pair < const std::ranked_symbol < SymbolType, RankType >, TAlphabet < SymbolType, RankType > > & kv : subMap ) { + TAlphabet < SymbolType, RankType > & substSet = kv.second; + + for ( auto eIter = substSet.begin ( ); eIter != substSet.end ( ); ) { + if ( alphabetK.count ( * eIter ) == 0 ) { + ++eIter; + } else { + auto it = subMap.find ( * eIter ); + size_t oldSize = substSet.size ( ); + substSet.insert ( it->second.begin ( ), it->second.end ( ) ); + change = ( oldSize != substSet.size ( ) ); // something was added + eIter = substSet.erase ( eIter ); + } + } + } +} + +template < class SymbolType, class RankType > +std::set < GlushkovFollowV3::TFollowTuple < SymbolType, RankType > > GlushkovFollowV3::replaceConstants ( const TAlphabet < SymbolType, RankType > & alphabetK, const std::vector < std::ranked_symbol < SymbolType, RankType > > & follow, const TSubstMap < SymbolType, RankType > & subMap2 ) { + TSubstMap < SymbolType, RankType > subMap ( subMap2 ); + preprocessSubMap ( alphabetK, subMap ); + + TFollowTuple < SymbolType, RankType > children_follow; + + for ( const std::ranked_symbol < SymbolType, RankType > & e : follow ) { + if ( alphabetK.count ( e ) > 0 ) + children_follow.push_back ( std::set < std::ranked_symbol < SymbolType, RankType > > ( subMap.at ( e ).begin ( ), subMap.at ( e ).end ( ) ) ); + else + children_follow.push_back ( std::set < std::ranked_symbol < SymbolType, RankType > > { e } ); + } + + return { children_follow }; +} + +// ----------------------------------------------------------------------------- + +template < class SymbolType, class RankType > +std::set < GlushkovFollowV3::TFollowTuple < SymbolType, RankType > > GlushkovFollowV3::Formal < SymbolType, RankType >::visit ( const rte::FormalRTEAlternation < SymbolType, RankType > & node, const std::ranked_symbol < SymbolType, RankType > & symbolF, const TAlphabet < SymbolType, RankType > & alphabetK, TSubstMap < SymbolType, RankType > & subMap ) { + std::set < TFollowTuple < SymbolType, RankType > > ret, tmp; + + tmp = node.getLeftElement ( ).template accept < std::set < TFollowTuple < SymbolType, RankType > >, GlushkovFollowV3::Formal < SymbolType, RankType > > ( symbolF, alphabetK, subMap ); + ret.insert ( tmp.begin ( ), tmp.end ( ) ); + + tmp = node.getRightElement ( ).template accept < std::set < TFollowTuple < SymbolType, RankType > >, GlushkovFollowV3::Formal < SymbolType, RankType > > ( symbolF, alphabetK, subMap ); + ret.insert ( tmp.begin ( ), tmp.end ( ) ); + + return ret; +} + +template < class SymbolType, class RankType > +std::set < GlushkovFollowV3::TFollowTuple < SymbolType, RankType > > GlushkovFollowV3::Formal < SymbolType, RankType >::visit ( const rte::FormalRTESubstitution < SymbolType, RankType > & node, const std::ranked_symbol < SymbolType, RankType > & symbolF, const TAlphabet < SymbolType, RankType > & alphabetK, TSubstMap < SymbolType, RankType > & subMap ) { + + TSubstMap < SymbolType, RankType > subMapLeft ( subMap ); + auto itMap = subMapLeft.find ( node.getSubstitutionSymbol ( ).getSymbol ( ) ); + + itMap->second.clear ( ); + + for ( const auto & s : node.getRightElement ( ).template accept < TAlphabet < SymbolType, RankType >, GlushkovFirst::Formal < SymbolType, RankType > > ( ) ) + itMap->second.insert ( s ); + + /* + * E sub F + * 1. if symbolF in F subtree, then Follow(F, symbolF); + * 2. if symbolF in E subtree, then Follow(E, symbolF); + */ + + if ( node.getLeftElement ( ).template accept < bool, GlushkovPos::Formal < SymbolType, RankType > > ( symbolF ) ) + return node.getLeftElement ( ).template accept < std::set < TFollowTuple < SymbolType, RankType > >, GlushkovFollowV3::Formal < SymbolType, RankType > > ( symbolF, alphabetK, subMapLeft ); + else + return node.getRightElement ( ).template accept < std::set < TFollowTuple < SymbolType, RankType > >, GlushkovFollowV3::Formal < SymbolType, RankType > > ( symbolF, alphabetK, subMap ); +} + +template < class SymbolType, class RankType > +std::set < GlushkovFollowV3::TFollowTuple < SymbolType, RankType > > GlushkovFollowV3::Formal < SymbolType, RankType >::visit ( const rte::FormalRTEIteration < SymbolType, RankType > & node, const std::ranked_symbol < SymbolType, RankType > & symbolF, const TAlphabet < SymbolType, RankType > & alphabetK, TSubstMap < SymbolType, RankType > & subMap ) { + + std::set < TFollowTuple < SymbolType, RankType > > ret; + + for ( const auto & s : node.getElement ( ).template accept < TAlphabet < SymbolType, RankType >, GlushkovFirst::Formal < SymbolType, RankType > > ( ) ) + subMap[node.getSubstitutionSymbol ( ).getSymbol ( )].insert ( s ); + + return node.getElement ( ).template accept < std::set < TFollowTuple < SymbolType, RankType > >, GlushkovFollowV3::Formal < SymbolType, RankType > > ( symbolF, alphabetK, subMap ); +} + +template < class SymbolType, class RankType > +std::set < GlushkovFollowV3::TFollowTuple < SymbolType, RankType > > GlushkovFollowV3::Formal < SymbolType, RankType >::visit ( const rte::FormalRTESymbolAlphabet < SymbolType, RankType > & node, const std::ranked_symbol < SymbolType, RankType > & symbolF, const TAlphabet < SymbolType, RankType > & alphabetK, TSubstMap < SymbolType, RankType > & subMap ) { + + std::set < TFollowTuple < SymbolType, RankType > > ret, tmp; + + if ( symbolF == node.getSymbol ( ) ) { + std::vector < std::ranked_symbol < SymbolType, RankType > > children; + + for ( const std::smart_ptr < const rte::FormalRTESymbol < SymbolType, RankType > > & c : node.getElements ( ) ) + children.push_back ( c->getSymbol ( ) ); + + return replaceConstants ( alphabetK, children, subMap ); + } + + for ( const auto & c : node.getElements ( ) ) { + tmp = c->template accept < std::set < TFollowTuple < SymbolType, RankType > >, GlushkovFollowV3::Formal < SymbolType, RankType > > ( symbolF, alphabetK, subMap ); + ret.insert ( tmp.begin ( ), tmp.end ( ) ); + } + + return ret; +} + +template < class SymbolType, class RankType > +std::set < GlushkovFollowV3::TFollowTuple < SymbolType, RankType > > GlushkovFollowV3::Formal < SymbolType, RankType >::visit ( const rte::FormalRTESymbolSubst < SymbolType, RankType > & /* node */, const std::ranked_symbol < SymbolType, RankType > & /* symbolF */, const TAlphabet < SymbolType, RankType > & /* alphabetK */, TSubstMap < SymbolType, RankType > & /* subMap */ ) { + return std::set < TFollowTuple < SymbolType, RankType > > ( ); +} + +template < class SymbolType, class RankType > +std::set < GlushkovFollowV3::TFollowTuple < SymbolType, RankType > > GlushkovFollowV3::Formal < SymbolType, RankType >::visit ( const rte::FormalRTEEmpty < SymbolType, RankType > & /* node */, const std::ranked_symbol < SymbolType, RankType > & /* symbolF */, const TAlphabet < SymbolType, RankType > & /* alphabetK */, TSubstMap < SymbolType, RankType > & /* subMap */ ) { + return std::set < TFollowTuple < SymbolType, RankType > > ( ); +} + +} /* namespace rte */ + +#endif /* RTE_GLUSHKOV_FOLLOW_V3_H_ */ diff --git a/alib2algo/src/rte/glushkov/GlushkovIndexate.cpp b/alib2algo/src/rte/glushkov/GlushkovIndexate.cpp index 1160fbe2a23cc0428dca6ecc7725e0f98750a87f..ca1aa06f0d8472d6ce5608b7ea481116b82f979a 100644 --- a/alib2algo/src/rte/glushkov/GlushkovIndexate.cpp +++ b/alib2algo/src/rte/glushkov/GlushkovIndexate.cpp @@ -13,6 +13,8 @@ namespace rte { +// ---------------------------------------------------------------------------- + std::ranked_symbol < > GlushkovIndexate::getSymbolFromGlushkovPair ( const std::ranked_symbol < > & symbol ) { const std::pair < DefaultSymbolType, DefaultSymbolType > & sps = ( ( const DefaultSymbolsPairType & ) symbol.getSymbol ( ).getData ( ) ); @@ -25,6 +27,8 @@ FormalRTE < > GlushkovIndexate::index ( const rte::FormalRTE < > & rte ) { return FormalRTE < > ( FormalRTEStructure < DefaultSymbolType, primitive::Unsigned > ( rte.getRTE ( ).getStructure ( ).accept < std::rvalue_ref < rte::FormalRTEElement < DefaultSymbolType, primitive::Unsigned > >, GlushkovIndexate::Formal > ( i ) ) ); } +// ---------------------------------------------------------------------------- + std::rvalue_ref < FormalRTEElement < DefaultSymbolType, primitive::Unsigned > > GlushkovIndexate::Formal::visit ( const rte::FormalRTESymbolAlphabet < DefaultSymbolType, primitive::Unsigned > & node, int & i ) { DefaultSymbolsPairType sps = DefaultSymbolsPairType ( std::make_pair ( DefaultSymbolType ( node.getSymbol ( ).getSymbol ( ) ), DefaultSymbolType ( i++ ) ) ); FormalRTESymbolAlphabet < DefaultSymbolType, primitive::Unsigned > * ns = new FormalRTESymbolAlphabet < DefaultSymbolType, primitive::Unsigned > ( std::ranked_symbol < > ( DefaultSymbolType ( sps ), node.getSymbol ( ).getRank ( ) ) ); @@ -62,4 +66,6 @@ std::rvalue_ref < FormalRTEElement < DefaultSymbolType, primitive::Unsigned > > return std::rvalue_ref < FormalRTEElement < DefaultSymbolType, primitive::Unsigned > > ( new FormalRTEEmpty < DefaultSymbolType, primitive::Unsigned > ( ) ); } +// ---------------------------------------------------------------------------- + } /* namespace rte */ diff --git a/alib2algo/src/rte/glushkov/GlushkovIndexate.h b/alib2algo/src/rte/glushkov/GlushkovIndexate.h index 30cf3db04a6904398d634b3f03f10ee8bcec2bba..c09f955821f9ade76c6529be1cff0bf832410e25 100644 --- a/alib2algo/src/rte/glushkov/GlushkovIndexate.h +++ b/alib2algo/src/rte/glushkov/GlushkovIndexate.h @@ -38,7 +38,6 @@ public: static std::rvalue_ref < FormalRTEElement < DefaultSymbolType, primitive::Unsigned > > visit ( const rte::FormalRTESymbolSubst < DefaultSymbolType, primitive::Unsigned > & node, int & i ); static std::rvalue_ref < FormalRTEElement < DefaultSymbolType, primitive::Unsigned > > visit ( const rte::FormalRTEEmpty < DefaultSymbolType, primitive::Unsigned > & node, int & i ); }; - }; } /* namespace rte */