diff --git a/alib2data/src/automaton/FSM/CompactNFA.cpp b/alib2data/src/automaton/FSM/CompactNFA.cpp index 91cffbd844abf17119ba54a661aad165441fd84d..c2eba0547d0d992806c066d1096f910c8298e608 100644 --- a/alib2data/src/automaton/FSM/CompactNFA.cpp +++ b/alib2data/src/automaton/FSM/CompactNFA.cpp @@ -10,7 +10,6 @@ #include "MultiInitialStateNFA.h" #include "NFA.h" #include "DFA.h" -#include "../AutomatonException.h" #include <ostream> #include <algorithm> #include <sstream> @@ -215,80 +214,6 @@ void CompactNFA::composeTransitions ( std::deque < sax::Token > & out ) const { } /* namespace automaton */ -namespace std { - -template < > -class ComponentConstraint2< automaton::CompactNFA, alphabet::Symbol, automaton::InputAlphabet > { -public: - static bool used ( const automaton::CompactNFA & automaton, const alphabet::Symbol & symbol ) { - for ( const std::pair < const std::pair < automaton::State, ::string::LinearString >, std::set < automaton::State > > & transition : automaton.getTransitions ( ) ) - if ( transition.first.second.getAlphabet ( ).count ( symbol ) ) - return true; - - return false; - } - - static bool available ( const automaton::CompactNFA &, const alphabet::Symbol & ) { - return true; - } - - static void valid ( const automaton::CompactNFA &, const alphabet::Symbol & ) { - } -}; - -template < > -class ComponentConstraint2< automaton::CompactNFA, automaton::State, automaton::States > { -public: - static bool used ( const automaton::CompactNFA & automaton, const automaton::State & state ) { - if ( automaton.getInitialState ( ) == state ) - return true; - - if ( automaton.getFinalStates ( ).count ( state ) ) - return true; - - for ( const std::pair < const std::pair < automaton::State, ::string::LinearString >, std::set < automaton::State > > & t : automaton.getTransitions ( ) ) - if ( ( t.first.first == state ) || t.second.count ( state ) ) - return true; - - return false; - } - - static bool available ( const automaton::CompactNFA &, const automaton::State & ) { - return true; - } - - static void valid ( const automaton::CompactNFA &, const automaton::State & ) { - } -}; - -template < > -class ComponentConstraint2< automaton::CompactNFA, automaton::State, automaton::FinalStates > { -public: - static bool used ( const automaton::CompactNFA &, const automaton::State & ) { - return false; - } - - static bool available ( const automaton::CompactNFA & automaton, const automaton::State & state ) { - return automaton.accessComponent < automaton::States > ( ).get ( ).count ( state ); - } - - static void valid ( const automaton::CompactNFA &, const automaton::State & ) { - } -}; - -template < > -class ElementConstraint2< automaton::CompactNFA, automaton::State, automaton::InitialState > { -public: - static bool available ( const automaton::CompactNFA & automaton, const automaton::State & state ) { - return automaton.accessComponent < automaton::States > ( ).get ( ).count ( state ); - } - - static void valid ( const automaton::CompactNFA &, const automaton::State & ) { - } -}; - -} /* namespace std */ - namespace alib { auto compactNFAParserRegister = xmlApi < automaton::Automaton >::ParserRegister < automaton::CompactNFA > ( ); diff --git a/alib2data/src/automaton/FSM/CompactNFA.h b/alib2data/src/automaton/FSM/CompactNFA.h index d5beb074ca6d1d29a21633feadc2c88867237fca..5452ee8403f89b0dfc1ed0087e0e06159ee3fe5d 100644 --- a/alib2data/src/automaton/FSM/CompactNFA.h +++ b/alib2data/src/automaton/FSM/CompactNFA.h @@ -8,6 +8,7 @@ #ifndef COMPACT_DFA_H_ #define COMPACT_DFA_H_ +#include "../AutomatonException.h" #include <map> #include <core/components2.hpp> #include "../AutomatonBase.h" @@ -164,4 +165,78 @@ public: } /* namespace automaton */ +namespace std { + +template < > +class ComponentConstraint2< automaton::CompactNFA, alphabet::Symbol, automaton::InputAlphabet > { +public: + static bool used ( const automaton::CompactNFA & automaton, const alphabet::Symbol & symbol ) { + for ( const std::pair < const std::pair < automaton::State, ::string::LinearString >, std::set < automaton::State > > & transition : automaton.getTransitions ( ) ) + if ( transition.first.second.getAlphabet ( ).count ( symbol ) ) + return true; + + return false; + } + + static bool available ( const automaton::CompactNFA &, const alphabet::Symbol & ) { + return true; + } + + static void valid ( const automaton::CompactNFA &, const alphabet::Symbol & ) { + } +}; + +template < > +class ComponentConstraint2< automaton::CompactNFA, automaton::State, automaton::States > { +public: + static bool used ( const automaton::CompactNFA & automaton, const automaton::State & state ) { + if ( automaton.getInitialState ( ) == state ) + return true; + + if ( automaton.getFinalStates ( ).count ( state ) ) + return true; + + for ( const std::pair < const std::pair < automaton::State, ::string::LinearString >, std::set < automaton::State > > & t : automaton.getTransitions ( ) ) + if ( ( t.first.first == state ) || t.second.count ( state ) ) + return true; + + return false; + } + + static bool available ( const automaton::CompactNFA &, const automaton::State & ) { + return true; + } + + static void valid ( const automaton::CompactNFA &, const automaton::State & ) { + } +}; + +template < > +class ComponentConstraint2< automaton::CompactNFA, automaton::State, automaton::FinalStates > { +public: + static bool used ( const automaton::CompactNFA &, const automaton::State & ) { + return false; + } + + static bool available ( const automaton::CompactNFA & automaton, const automaton::State & state ) { + return automaton.accessComponent < automaton::States > ( ).get ( ).count ( state ); + } + + static void valid ( const automaton::CompactNFA &, const automaton::State & ) { + } +}; + +template < > +class ElementConstraint2< automaton::CompactNFA, automaton::State, automaton::InitialState > { +public: + static bool available ( const automaton::CompactNFA & automaton, const automaton::State & state ) { + return automaton.accessComponent < automaton::States > ( ).get ( ).count ( state ); + } + + static void valid ( const automaton::CompactNFA &, const automaton::State & ) { + } +}; + +} /* namespace std */ + #endif /* COMPACT_DFA_H_ */ diff --git a/alib2data/src/automaton/FSM/DFA.cpp b/alib2data/src/automaton/FSM/DFA.cpp index 65773b1e44a56d308c5274e7ec1ffe57c000e714..676c9233e14dba02a15ef2762ce8a3ed2573f36a 100644 --- a/alib2data/src/automaton/FSM/DFA.cpp +++ b/alib2data/src/automaton/FSM/DFA.cpp @@ -6,7 +6,6 @@ */ #include "DFA.h" -#include "../AutomatonException.h" #include <ostream> #include <sstream> @@ -188,80 +187,6 @@ void DFA::composeTransitions ( std::deque < sax::Token > & out ) const { } /* namespace automaton */ -namespace std { - -template < > -class ComponentConstraint2< automaton::DFA, alphabet::Symbol, automaton::InputAlphabet > { -public: - static bool used ( const automaton::DFA & automaton, const alphabet::Symbol & symbol ) { - for ( const std::pair < const std::pair < automaton::State, alphabet::Symbol >, automaton::State > & transition : automaton.getTransitions ( ) ) - if ( transition.first.second == symbol ) - return true; - - return false; - } - - static bool available ( const automaton::DFA &, const alphabet::Symbol & ) { - return true; - } - - static void valid ( const automaton::DFA &, const alphabet::Symbol & ) { - } -}; - -template < > -class ComponentConstraint2< automaton::DFA, automaton::State, automaton::States > { -public: - static bool used ( const automaton::DFA & automaton, const automaton::State & state ) { - if ( automaton.getInitialState ( ) == state ) - return true; - - if ( automaton.getFinalStates ( ).count ( state ) ) - return true; - - for ( const std::pair < const std::pair < automaton::State, alphabet::Symbol >, automaton::State > & t : automaton.getTransitions ( ) ) - if ( ( t.first.first == state ) || ( t.second == state ) ) - return true; - - return false; - } - - static bool available ( const automaton::DFA &, const automaton::State & ) { - return true; - } - - static void valid ( const automaton::DFA &, const automaton::State & ) { - } -}; - -template < > -class ComponentConstraint2< automaton::DFA, automaton::State, automaton::FinalStates > { -public: - static bool used ( const automaton::DFA &, const automaton::State & ) { - return false; - } - - static bool available ( const automaton::DFA & automaton, const automaton::State & state ) { - return automaton.accessComponent < automaton::States > ( ).get ( ).count ( state ); - } - - static void valid ( const automaton::DFA &, const automaton::State & ) { - } -}; - -template < > -class ElementConstraint2< automaton::DFA, automaton::State, automaton::InitialState > { -public: - static bool available ( const automaton::DFA & automaton, const automaton::State & state ) { - return automaton.accessComponent < automaton::States > ( ).get ( ).count ( state ); - } - - static void valid ( const automaton::DFA &, const automaton::State & ) { - } -}; - -} /* namespace std */ - namespace alib { auto DFAParserRegister = xmlApi < automaton::Automaton >::ParserRegister < automaton::DFA > ( ); diff --git a/alib2data/src/automaton/FSM/DFA.h b/alib2data/src/automaton/FSM/DFA.h index 17a55b5fa81de55dabb3d630dca708ef7bc5120a..0660b4680fa16f78317497ed7c0bfc9434bebc39 100644 --- a/alib2data/src/automaton/FSM/DFA.h +++ b/alib2data/src/automaton/FSM/DFA.h @@ -8,6 +8,7 @@ #ifndef DFA_H_ #define DFA_H_ +#include "../AutomatonException.h" #include <map> #include <core/components2.hpp> #include "../AutomatonBase.h" @@ -164,4 +165,78 @@ public: } /* namespace automaton */ +namespace std { + +template < > +class ComponentConstraint2< automaton::DFA, alphabet::Symbol, automaton::InputAlphabet > { +public: + static bool used ( const automaton::DFA & automaton, const alphabet::Symbol & symbol ) { + for ( const std::pair < const std::pair < automaton::State, alphabet::Symbol >, automaton::State > & transition : automaton.getTransitions ( ) ) + if ( transition.first.second == symbol ) + return true; + + return false; + } + + static bool available ( const automaton::DFA &, const alphabet::Symbol & ) { + return true; + } + + static void valid ( const automaton::DFA &, const alphabet::Symbol & ) { + } +}; + +template < > +class ComponentConstraint2< automaton::DFA, automaton::State, automaton::States > { +public: + static bool used ( const automaton::DFA & automaton, const automaton::State & state ) { + if ( automaton.getInitialState ( ) == state ) + return true; + + if ( automaton.getFinalStates ( ).count ( state ) ) + return true; + + for ( const std::pair < const std::pair < automaton::State, alphabet::Symbol >, automaton::State > & t : automaton.getTransitions ( ) ) + if ( ( t.first.first == state ) || ( t.second == state ) ) + return true; + + return false; + } + + static bool available ( const automaton::DFA &, const automaton::State & ) { + return true; + } + + static void valid ( const automaton::DFA &, const automaton::State & ) { + } +}; + +template < > +class ComponentConstraint2< automaton::DFA, automaton::State, automaton::FinalStates > { +public: + static bool used ( const automaton::DFA &, const automaton::State & ) { + return false; + } + + static bool available ( const automaton::DFA & automaton, const automaton::State & state ) { + return automaton.accessComponent < automaton::States > ( ).get ( ).count ( state ); + } + + static void valid ( const automaton::DFA &, const automaton::State & ) { + } +}; + +template < > +class ElementConstraint2< automaton::DFA, automaton::State, automaton::InitialState > { +public: + static bool available ( const automaton::DFA & automaton, const automaton::State & state ) { + return automaton.accessComponent < automaton::States > ( ).get ( ).count ( state ); + } + + static void valid ( const automaton::DFA &, const automaton::State & ) { + } +}; + +} /* namespace std */ + #endif /* DFA_H_ */ diff --git a/alib2data/src/automaton/FSM/EpsilonNFA.cpp b/alib2data/src/automaton/FSM/EpsilonNFA.cpp index 3da8e8985c54898798efcb2a7d73f505b64fcf7a..99ee59dffe918e070b1bafed1985a851cf3450b5 100644 --- a/alib2data/src/automaton/FSM/EpsilonNFA.cpp +++ b/alib2data/src/automaton/FSM/EpsilonNFA.cpp @@ -9,8 +9,6 @@ #include "MultiInitialStateNFA.h" #include "NFA.h" #include "DFA.h" -#include "../AutomatonException.h" -#include "../Automaton.h" #include <ostream> #include <sstream> @@ -312,80 +310,6 @@ void EpsilonNFA::composeTransitions ( std::deque < sax::Token > & out ) const { } /* namespace automaton */ -namespace std { - -template < > -class ComponentConstraint2< automaton::EpsilonNFA, alphabet::Symbol, automaton::InputAlphabet > { -public: - static bool used ( const automaton::EpsilonNFA & automaton, const alphabet::Symbol & symbol ) { - for ( const std::pair < const std::pair < automaton::State, std::variant < ::string::Epsilon, alphabet::Symbol > >, std::set < automaton::State > > & transition : automaton.getTransitions ( ) ) - if ( transition.first.second.is < alphabet::Symbol > ( ) && ( transition.first.second.get < alphabet::Symbol > ( ) == symbol ) ) - return true; - - return false; - } - - static bool available ( const automaton::EpsilonNFA &, const alphabet::Symbol & ) { - return true; - } - - static void valid ( const automaton::EpsilonNFA &, const alphabet::Symbol & ) { - } -}; - -template < > -class ComponentConstraint2< automaton::EpsilonNFA, automaton::State, automaton::States > { -public: - static bool used ( const automaton::EpsilonNFA & automaton, const automaton::State & state ) { - if ( automaton.getInitialState ( ) == state ) - return true; - - if ( automaton.getFinalStates ( ).count ( state ) ) - return true; - - for ( const std::pair < const std::pair < automaton::State, std::variant < ::string::Epsilon, alphabet::Symbol > >, std::set < automaton::State > > & transition : automaton.getTransitions ( ) ) - if ( ( transition.first.first == state ) || transition.second.count ( state ) ) - return true; - - return false; - } - - static bool available ( const automaton::EpsilonNFA &, const automaton::State & ) { - return true; - } - - static void valid ( const automaton::EpsilonNFA &, const automaton::State & ) { - } -}; - -template < > -class ComponentConstraint2< automaton::EpsilonNFA, automaton::State, automaton::FinalStates > { -public: - static bool used ( const automaton::EpsilonNFA &, const automaton::State & ) { - return false; - } - - static bool available ( const automaton::EpsilonNFA & automaton, const automaton::State & state ) { - return automaton.accessComponent < automaton::States > ( ).get ( ).count ( state ); - } - - static void valid ( const automaton::EpsilonNFA &, const automaton::State & ) { - } -}; - -template < > -class ElementConstraint2< automaton::EpsilonNFA, automaton::State, automaton::InitialState > { -public: - static bool available ( const automaton::EpsilonNFA & automaton, const automaton::State & state ) { - return automaton.accessComponent < automaton::States > ( ).get ( ).count ( state ); - } - - static void valid ( const automaton::EpsilonNFA &, const automaton::State & ) { - } -}; - -} /* namespace std */ - namespace alib { auto epsilonNFAParserRegister = xmlApi < automaton::Automaton >::ParserRegister < automaton::EpsilonNFA > ( ); diff --git a/alib2data/src/automaton/FSM/EpsilonNFA.h b/alib2data/src/automaton/FSM/EpsilonNFA.h index 4fa7c5e91077d6c332af90fc33bb064b3fa38367..2c767668c0029e9da67593b1a954a9a5b42b7e32 100644 --- a/alib2data/src/automaton/FSM/EpsilonNFA.h +++ b/alib2data/src/automaton/FSM/EpsilonNFA.h @@ -8,6 +8,7 @@ #ifndef EPSILON_NFA_H_ #define EPSILON_NFA_H_ +#include "../AutomatonException.h" #include <map> #include <variant> #include <core/components2.hpp> @@ -240,4 +241,78 @@ public: } /* namespace automaton */ +namespace std { + +template < > +class ComponentConstraint2< automaton::EpsilonNFA, alphabet::Symbol, automaton::InputAlphabet > { +public: + static bool used ( const automaton::EpsilonNFA & automaton, const alphabet::Symbol & symbol ) { + for ( const std::pair < const std::pair < automaton::State, std::variant < ::string::Epsilon, alphabet::Symbol > >, std::set < automaton::State > > & transition : automaton.getTransitions ( ) ) + if ( transition.first.second.is < alphabet::Symbol > ( ) && ( transition.first.second.get < alphabet::Symbol > ( ) == symbol ) ) + return true; + + return false; + } + + static bool available ( const automaton::EpsilonNFA &, const alphabet::Symbol & ) { + return true; + } + + static void valid ( const automaton::EpsilonNFA &, const alphabet::Symbol & ) { + } +}; + +template < > +class ComponentConstraint2< automaton::EpsilonNFA, automaton::State, automaton::States > { +public: + static bool used ( const automaton::EpsilonNFA & automaton, const automaton::State & state ) { + if ( automaton.getInitialState ( ) == state ) + return true; + + if ( automaton.getFinalStates ( ).count ( state ) ) + return true; + + for ( const std::pair < const std::pair < automaton::State, std::variant < ::string::Epsilon, alphabet::Symbol > >, std::set < automaton::State > > & transition : automaton.getTransitions ( ) ) + if ( ( transition.first.first == state ) || transition.second.count ( state ) ) + return true; + + return false; + } + + static bool available ( const automaton::EpsilonNFA &, const automaton::State & ) { + return true; + } + + static void valid ( const automaton::EpsilonNFA &, const automaton::State & ) { + } +}; + +template < > +class ComponentConstraint2< automaton::EpsilonNFA, automaton::State, automaton::FinalStates > { +public: + static bool used ( const automaton::EpsilonNFA &, const automaton::State & ) { + return false; + } + + static bool available ( const automaton::EpsilonNFA & automaton, const automaton::State & state ) { + return automaton.accessComponent < automaton::States > ( ).get ( ).count ( state ); + } + + static void valid ( const automaton::EpsilonNFA &, const automaton::State & ) { + } +}; + +template < > +class ElementConstraint2< automaton::EpsilonNFA, automaton::State, automaton::InitialState > { +public: + static bool available ( const automaton::EpsilonNFA & automaton, const automaton::State & state ) { + return automaton.accessComponent < automaton::States > ( ).get ( ).count ( state ); + } + + static void valid ( const automaton::EpsilonNFA &, const automaton::State & ) { + } +}; + +} /* namespace std */ + #endif /* EPSILON_NFA_H_ */ diff --git a/alib2data/src/automaton/FSM/ExtendedNFA.cpp b/alib2data/src/automaton/FSM/ExtendedNFA.cpp index a0acd6a0874eef16424f11dc242784be92a3d887..81ae24b425552488e6623edfda13aa7537ad4955 100644 --- a/alib2data/src/automaton/FSM/ExtendedNFA.cpp +++ b/alib2data/src/automaton/FSM/ExtendedNFA.cpp @@ -11,8 +11,6 @@ #include "MultiInitialStateNFA.h" #include "NFA.h" #include "DFA.h" -#include "../AutomatonException.h" -#include "../Automaton.h" #include "../../regexp/RegExp.h" #include <ostream> #include <algorithm> @@ -225,80 +223,6 @@ void ExtendedNFA::composeTransitions ( std::deque < sax::Token > & out ) const { } /* namespace automaton */ -namespace std { - -template < > -class ComponentConstraint2< automaton::ExtendedNFA, alphabet::Symbol, automaton::InputAlphabet > { -public: - static bool used ( const automaton::ExtendedNFA & automaton, const alphabet::Symbol & symbol ) { - for ( const std::pair < const std::pair < automaton::State, regexp::RegExp >, std::set < automaton::State > > & transition : automaton.getTransitions ( ) ) - if ( transition.first.second.getAlphabet ( ).count ( symbol ) == 1 ) - return true; - - return false; - } - - static bool available ( const automaton::ExtendedNFA &, const alphabet::Symbol & ) { - return true; - } - - static void valid ( const automaton::ExtendedNFA &, const alphabet::Symbol & ) { - } -}; - -template < > -class ComponentConstraint2< automaton::ExtendedNFA, automaton::State, automaton::States > { -public: - static bool used ( const automaton::ExtendedNFA & automaton, const automaton::State & state ) { - if ( automaton.getInitialState ( ) == state ) - return true; - - if ( automaton.getFinalStates ( ).count ( state ) ) - return true; - - for ( const std::pair < const std::pair < automaton::State, regexp::RegExp >, std::set < automaton::State > > & transition : automaton.getTransitions ( ) ) - if ( ( transition.first.first == state ) || ( transition.second.find ( state ) != transition.second.end ( ) ) ) - return true; - - return false; - } - - static bool available ( const automaton::ExtendedNFA &, const automaton::State & ) { - return true; - } - - static void valid ( const automaton::ExtendedNFA &, const automaton::State & ) { - } -}; - -template < > -class ComponentConstraint2< automaton::ExtendedNFA, automaton::State, automaton::FinalStates > { -public: - static bool used ( const automaton::ExtendedNFA &, const automaton::State & ) { - return false; -} - - static bool available ( const automaton::ExtendedNFA & automaton, const automaton::State & state ) { - return automaton.accessComponent < automaton::States > ( ).get ( ).count ( state ); - } - - static void valid ( const automaton::ExtendedNFA &, const automaton::State & ) { - } -}; - -template < > -class ElementConstraint2< automaton::ExtendedNFA, automaton::State, automaton::InitialState > { -public: - static bool available ( const automaton::ExtendedNFA & automaton, const automaton::State & state ) { - return automaton.accessComponent < automaton::States > ( ).get ( ).count ( state ); - } - - static void valid ( const automaton::ExtendedNFA &, const automaton::State & ) { - } -}; - -} /* namespace std */ - namespace alib { auto extendedNFAParserRegister = xmlApi < automaton::Automaton >::ParserRegister < automaton::ExtendedNFA > ( ); diff --git a/alib2data/src/automaton/FSM/ExtendedNFA.h b/alib2data/src/automaton/FSM/ExtendedNFA.h index 8503db403c141b687d4c25a26f5cfb055f737443..996a107cce7b03044ceb3b863a13f5ec48e7ad0c 100644 --- a/alib2data/src/automaton/FSM/ExtendedNFA.h +++ b/alib2data/src/automaton/FSM/ExtendedNFA.h @@ -8,6 +8,7 @@ #ifndef EXTENDED_NFA_H_ #define EXTENDED_NFA_H_ +#include "../AutomatonException.h" #include <map> #include <core/components.hpp> #include "../AutomatonBase.h" @@ -165,4 +166,78 @@ public: } /* namespace automaton */ +namespace std { + +template < > +class ComponentConstraint2< automaton::ExtendedNFA, alphabet::Symbol, automaton::InputAlphabet > { +public: + static bool used ( const automaton::ExtendedNFA & automaton, const alphabet::Symbol & symbol ) { + for ( const std::pair < const std::pair < automaton::State, regexp::RegExp >, std::set < automaton::State > > & transition : automaton.getTransitions ( ) ) + if ( transition.first.second.getAlphabet ( ).count ( symbol ) == 1 ) + return true; + + return false; + } + + static bool available ( const automaton::ExtendedNFA &, const alphabet::Symbol & ) { + return true; + } + + static void valid ( const automaton::ExtendedNFA &, const alphabet::Symbol & ) { + } +}; + +template < > +class ComponentConstraint2< automaton::ExtendedNFA, automaton::State, automaton::States > { +public: + static bool used ( const automaton::ExtendedNFA & automaton, const automaton::State & state ) { + if ( automaton.getInitialState ( ) == state ) + return true; + + if ( automaton.getFinalStates ( ).count ( state ) ) + return true; + + for ( const std::pair < const std::pair < automaton::State, regexp::RegExp >, std::set < automaton::State > > & transition : automaton.getTransitions ( ) ) + if ( ( transition.first.first == state ) || ( transition.second.find ( state ) != transition.second.end ( ) ) ) + return true; + + return false; + } + + static bool available ( const automaton::ExtendedNFA &, const automaton::State & ) { + return true; + } + + static void valid ( const automaton::ExtendedNFA &, const automaton::State & ) { + } +}; + +template < > +class ComponentConstraint2< automaton::ExtendedNFA, automaton::State, automaton::FinalStates > { +public: + static bool used ( const automaton::ExtendedNFA &, const automaton::State & ) { + return false; +} + + static bool available ( const automaton::ExtendedNFA & automaton, const automaton::State & state ) { + return automaton.accessComponent < automaton::States > ( ).get ( ).count ( state ); + } + + static void valid ( const automaton::ExtendedNFA &, const automaton::State & ) { + } +}; + +template < > +class ElementConstraint2< automaton::ExtendedNFA, automaton::State, automaton::InitialState > { +public: + static bool available ( const automaton::ExtendedNFA & automaton, const automaton::State & state ) { + return automaton.accessComponent < automaton::States > ( ).get ( ).count ( state ); + } + + static void valid ( const automaton::ExtendedNFA &, const automaton::State & ) { + } +}; + +} /* namespace std */ + #endif /* EXTENDED_NFA_H_ */ diff --git a/alib2data/src/automaton/FSM/MultiInitialStateNFA.cpp b/alib2data/src/automaton/FSM/MultiInitialStateNFA.cpp index c6df9881c01f756b0eb18b2357973524502b63f8..371bb6cddc7c8272cc1ffdc8dd0a086c946b833c 100644 --- a/alib2data/src/automaton/FSM/MultiInitialStateNFA.cpp +++ b/alib2data/src/automaton/FSM/MultiInitialStateNFA.cpp @@ -8,7 +8,6 @@ #include "MultiInitialStateNFA.h" #include "NFA.h" #include "DFA.h" -#include "../AutomatonException.h" #include <ostream> #include <sstream> @@ -205,84 +204,6 @@ void MultiInitialStateNFA::composeTransitions ( std::deque < sax::Token > & out } /* namespace automaton */ -namespace std { - -template < > -class ComponentConstraint2< automaton::MultiInitialStateNFA, alphabet::Symbol, automaton::InputAlphabet > { -public: - static bool used ( const automaton::MultiInitialStateNFA & automaton, const alphabet::Symbol & symbol ) { - for ( const std::pair < const std::pair < automaton::State, alphabet::Symbol >, std::set < automaton::State > > & transition : automaton.getTransitions ( ) ) - if ( transition.first.second == symbol ) - return true; - - return false; - } - - static bool available ( const automaton::MultiInitialStateNFA &, const alphabet::Symbol & ) { - return true; - } - - static void valid ( const automaton::MultiInitialStateNFA &, const alphabet::Symbol & ) { - } -}; - -template < > -class ComponentConstraint2< automaton::MultiInitialStateNFA, automaton::State, automaton::States > { -public: - static bool used ( const automaton::MultiInitialStateNFA & automaton, const automaton::State & state ) { - if ( automaton.getInitialStates ( ).count ( state ) ) - return true; - - if ( automaton.getFinalStates ( ).count ( state ) ) - return true; - - for ( const std::pair < const std::pair < automaton::State, alphabet::Symbol >, std::set < automaton::State > > & transition : automaton.getTransitions ( ) ) - if ( ( transition.first.first == state ) || ( transition.second.find ( state ) != transition.second.end ( ) ) ) - return true; - - return false; - } - - static bool available ( const automaton::MultiInitialStateNFA &, const automaton::State & ) { - return true; - } - - static void valid ( const automaton::MultiInitialStateNFA &, const automaton::State & ) { - } -}; - -template < > -class ComponentConstraint2< automaton::MultiInitialStateNFA, automaton::State, automaton::FinalStates > { -public: - static bool used ( const automaton::MultiInitialStateNFA &, const automaton::State & ) { - return false; - } - - static bool available ( const automaton::MultiInitialStateNFA & automaton, const automaton::State & state ) { - return automaton.accessComponent < automaton::States > ( ).get ( ).count ( state ); - } - - static void valid ( const automaton::MultiInitialStateNFA &, const automaton::State & ) { - } -}; - -template < > -class ComponentConstraint2< automaton::MultiInitialStateNFA, automaton::State, automaton::InitialStates > { -public: - static bool used ( const automaton::MultiInitialStateNFA &, const automaton::State & ) { - return false; - } - - static bool available ( const automaton::MultiInitialStateNFA & automaton, const automaton::State & state ) { - return automaton.accessComponent < automaton::States > ( ).get ( ).count ( state ); - } - - static void valid ( const automaton::MultiInitialStateNFA &, const automaton::State & ) { - } -}; - -} /* namespace std */ - namespace alib { auto multiInitialStateNFAParserRegister = xmlApi < automaton::Automaton >::ParserRegister < automaton::MultiInitialStateNFA > ( ); diff --git a/alib2data/src/automaton/FSM/MultiInitialStateNFA.h b/alib2data/src/automaton/FSM/MultiInitialStateNFA.h index c252e15b1aa684df66e49f8f45b68db3d2e9e4bb..2cd5835b4289241b0ba9b272a5dc7e6c8ecb764b 100644 --- a/alib2data/src/automaton/FSM/MultiInitialStateNFA.h +++ b/alib2data/src/automaton/FSM/MultiInitialStateNFA.h @@ -8,6 +8,7 @@ #ifndef MULTI_INITIAL_STATE_NFA_H_ #define MULTI_INITIAL_STATE_NFA_H_ +#include "../AutomatonException.h" #include <map> #include <core/components2.hpp> #include "../AutomatonBase.h" @@ -184,4 +185,82 @@ public: } /* namespace automaton */ +namespace std { + +template < > +class ComponentConstraint2< automaton::MultiInitialStateNFA, alphabet::Symbol, automaton::InputAlphabet > { +public: + static bool used ( const automaton::MultiInitialStateNFA & automaton, const alphabet::Symbol & symbol ) { + for ( const std::pair < const std::pair < automaton::State, alphabet::Symbol >, std::set < automaton::State > > & transition : automaton.getTransitions ( ) ) + if ( transition.first.second == symbol ) + return true; + + return false; + } + + static bool available ( const automaton::MultiInitialStateNFA &, const alphabet::Symbol & ) { + return true; + } + + static void valid ( const automaton::MultiInitialStateNFA &, const alphabet::Symbol & ) { + } +}; + +template < > +class ComponentConstraint2< automaton::MultiInitialStateNFA, automaton::State, automaton::States > { +public: + static bool used ( const automaton::MultiInitialStateNFA & automaton, const automaton::State & state ) { + if ( automaton.getInitialStates ( ).count ( state ) ) + return true; + + if ( automaton.getFinalStates ( ).count ( state ) ) + return true; + + for ( const std::pair < const std::pair < automaton::State, alphabet::Symbol >, std::set < automaton::State > > & transition : automaton.getTransitions ( ) ) + if ( ( transition.first.first == state ) || ( transition.second.find ( state ) != transition.second.end ( ) ) ) + return true; + + return false; + } + + static bool available ( const automaton::MultiInitialStateNFA &, const automaton::State & ) { + return true; + } + + static void valid ( const automaton::MultiInitialStateNFA &, const automaton::State & ) { + } +}; + +template < > +class ComponentConstraint2< automaton::MultiInitialStateNFA, automaton::State, automaton::FinalStates > { +public: + static bool used ( const automaton::MultiInitialStateNFA &, const automaton::State & ) { + return false; + } + + static bool available ( const automaton::MultiInitialStateNFA & automaton, const automaton::State & state ) { + return automaton.accessComponent < automaton::States > ( ).get ( ).count ( state ); + } + + static void valid ( const automaton::MultiInitialStateNFA &, const automaton::State & ) { + } +}; + +template < > +class ComponentConstraint2< automaton::MultiInitialStateNFA, automaton::State, automaton::InitialStates > { +public: + static bool used ( const automaton::MultiInitialStateNFA &, const automaton::State & ) { + return false; + } + + static bool available ( const automaton::MultiInitialStateNFA & automaton, const automaton::State & state ) { + return automaton.accessComponent < automaton::States > ( ).get ( ).count ( state ); + } + + static void valid ( const automaton::MultiInitialStateNFA &, const automaton::State & ) { + } +}; + +} /* namespace std */ + #endif /* MULTI_INITIAL_STATE_NFA_H_ */ diff --git a/alib2data/src/automaton/FSM/NFA.cpp b/alib2data/src/automaton/FSM/NFA.cpp index 5daa3d7eb88596e05224d8517ed5cde139ca5350..9c2e9f68e83ec56b6190eeca89f153bd584f876e 100644 --- a/alib2data/src/automaton/FSM/NFA.cpp +++ b/alib2data/src/automaton/FSM/NFA.cpp @@ -6,7 +6,6 @@ */ #include "NFA.h" -#include "../AutomatonException.h" #include <ostream> #include <sstream> @@ -197,80 +196,6 @@ void NFA::composeTransitions ( std::deque < sax::Token > & out ) const { } /* namespace automaton */ -namespace std { - -template < > -class ComponentConstraint2< automaton::NFA, alphabet::Symbol, automaton::InputAlphabet > { -public: - static bool used ( const automaton::NFA & automaton, const alphabet::Symbol & symbol ) { - for ( const std::pair < const std::pair < automaton::State, alphabet::Symbol >, std::set < automaton::State > > & transition : automaton.getTransitions ( ) ) - if ( transition.first.second == symbol ) - return true; - - return false; - } - - static bool available ( const automaton::NFA &, const alphabet::Symbol & ) { - return true; - } - - static void valid ( const automaton::NFA &, const alphabet::Symbol & ) { - } -}; - -template < > -class ComponentConstraint2< automaton::NFA, automaton::State, automaton::States > { -public: - static bool used ( const automaton::NFA & automaton, const automaton::State & state ) { - if ( automaton.getInitialState ( ) == state ) - return true; - - if ( automaton.getFinalStates ( ).count ( state ) ) - return true; - - for ( const std::pair < const std::pair < automaton::State, alphabet::Symbol >, std::set < automaton::State > > & transition : automaton.getTransitions ( ) ) - if ( ( transition.first.first == state ) || ( transition.second.find ( state ) != transition.second.end ( ) ) ) - return true; - - return false; - } - - static bool available ( const automaton::NFA &, const automaton::State & ) { - return true; - } - - static void valid ( const automaton::NFA &, const automaton::State & ) { - } -}; - -template < > -class ComponentConstraint2< automaton::NFA, automaton::State, automaton::FinalStates > { -public: - static bool used ( const automaton::NFA &, const automaton::State & ) { - return false; - } - - static bool available ( const automaton::NFA & automaton, const automaton::State & state ) { - return automaton.accessComponent < automaton::States > ( ).get ( ).count ( state ); - } - - static void valid ( const automaton::NFA &, const automaton::State & ) { - } -}; - -template < > -class ElementConstraint2< automaton::NFA, automaton::State, automaton::InitialState > { -public: - static bool available ( const automaton::NFA & automaton, const automaton::State & state ) { - return automaton.accessComponent < automaton::States > ( ).get ( ).count ( state ); - } - - static void valid ( const automaton::NFA &, const automaton::State & ) { - } -}; - -} /* namespace std */ - namespace alib { auto NFAParserRegister = xmlApi < automaton::Automaton >::ParserRegister < automaton::NFA > ( ); diff --git a/alib2data/src/automaton/FSM/NFA.h b/alib2data/src/automaton/FSM/NFA.h index 8e9e180af82cc883873a40a2719e725416195533..e563d6222ff97bf5ed71e7ae59fb4a4b3e424212 100644 --- a/alib2data/src/automaton/FSM/NFA.h +++ b/alib2data/src/automaton/FSM/NFA.h @@ -8,6 +8,7 @@ #ifndef NFA_H_ #define NFA_H_ +#include "../AutomatonException.h" #include <map> #include <core/components2.hpp> #include "../AutomatonBase.h" @@ -178,4 +179,78 @@ public: } /* namespace automaton */ +namespace std { + +template < > +class ComponentConstraint2< automaton::NFA, alphabet::Symbol, automaton::InputAlphabet > { +public: + static bool used ( const automaton::NFA & automaton, const alphabet::Symbol & symbol ) { + for ( const std::pair < const std::pair < automaton::State, alphabet::Symbol >, std::set < automaton::State > > & transition : automaton.getTransitions ( ) ) + if ( transition.first.second == symbol ) + return true; + + return false; + } + + static bool available ( const automaton::NFA &, const alphabet::Symbol & ) { + return true; + } + + static void valid ( const automaton::NFA &, const alphabet::Symbol & ) { + } +}; + +template < > +class ComponentConstraint2< automaton::NFA, automaton::State, automaton::States > { +public: + static bool used ( const automaton::NFA & automaton, const automaton::State & state ) { + if ( automaton.getInitialState ( ) == state ) + return true; + + if ( automaton.getFinalStates ( ).count ( state ) ) + return true; + + for ( const std::pair < const std::pair < automaton::State, alphabet::Symbol >, std::set < automaton::State > > & transition : automaton.getTransitions ( ) ) + if ( ( transition.first.first == state ) || ( transition.second.find ( state ) != transition.second.end ( ) ) ) + return true; + + return false; + } + + static bool available ( const automaton::NFA &, const automaton::State & ) { + return true; + } + + static void valid ( const automaton::NFA &, const automaton::State & ) { + } +}; + +template < > +class ComponentConstraint2< automaton::NFA, automaton::State, automaton::FinalStates > { +public: + static bool used ( const automaton::NFA &, const automaton::State & ) { + return false; + } + + static bool available ( const automaton::NFA & automaton, const automaton::State & state ) { + return automaton.accessComponent < automaton::States > ( ).get ( ).count ( state ); + } + + static void valid ( const automaton::NFA &, const automaton::State & ) { + } +}; + +template < > +class ElementConstraint2< automaton::NFA, automaton::State, automaton::InitialState > { +public: + static bool available ( const automaton::NFA & automaton, const automaton::State & state ) { + return automaton.accessComponent < automaton::States > ( ).get ( ).count ( state ); + } + + static void valid ( const automaton::NFA &, const automaton::State & ) { + } +}; + +} /* namespace std */ + #endif /* NFA_H_ */ diff --git a/alib2data/src/automaton/PDA/DPDA.cpp b/alib2data/src/automaton/PDA/DPDA.cpp index 5458244e7106a55b3d753cd49520ab25d9fe3475..23918f00b93d20ea6e956afca93640542cf6f1e6 100644 --- a/alib2data/src/automaton/PDA/DPDA.cpp +++ b/alib2data/src/automaton/PDA/DPDA.cpp @@ -6,7 +6,6 @@ */ #include "DPDA.h" -#include "../AutomatonException.h" #include <algorithm> #include <sstream> @@ -278,116 +277,6 @@ void DPDA::composeTransitions(std::deque<sax::Token>& out) const { } /* namespace automaton */ -namespace std { - -template < > -class ComponentConstraint2< automaton::DPDA, alphabet::Symbol, automaton::InputAlphabet > { -public: - static bool used ( const automaton::DPDA & automaton, const alphabet::Symbol & symbol ) { - for (const std::pair<const std::tuple<automaton::State, std::variant<::string::Epsilon, alphabet::Symbol>, std::vector<alphabet::Symbol> >, std::pair<automaton::State, std::vector<alphabet::Symbol> > >& transition : automaton.getTransitions()) - if (std::get<1>(transition.first).is<alphabet::Symbol>() && symbol == std::get<1>(transition.first).get<alphabet::Symbol>()) - return true; - - return false; - } - - static bool available ( const automaton::DPDA &, const alphabet::Symbol & ) { - return true; - } - - static void valid ( const automaton::DPDA &, const alphabet::Symbol & ) { - } -}; - -template < > -class ComponentConstraint2< automaton::DPDA, alphabet::Symbol, automaton::PushdownStoreAlphabet > { -public: - static bool used ( const automaton::DPDA & automaton, const alphabet::Symbol & symbol ) { - if(automaton.getInitialSymbol() == symbol) - return true; - - for (const std::pair<const std::tuple<automaton::State, std::variant<::string::Epsilon, alphabet::Symbol>, std::vector<alphabet::Symbol> >, std::pair<automaton::State, std::vector<alphabet::Symbol> > >& transition : automaton.getTransitions()) { - const auto & popSymbols = std::get<2>(transition.first); - const auto & pushSymbols = transition.second.second; - if(std::contains(popSymbols.begin(), popSymbols.end(), symbol ) || std::contains(pushSymbols.begin(), pushSymbols.end(), symbol)) - return true; - } - - return false; - } - - static bool available ( const automaton::DPDA &, const alphabet::Symbol & ) { - return true; - } - - static void valid ( const automaton::DPDA &, const alphabet::Symbol & ) { - } -}; - -template < > -class ElementConstraint2< automaton::DPDA, alphabet::Symbol, automaton::InitialSymbol > { -public: - static bool available ( const automaton::DPDA & automaton, const alphabet::Symbol & symbol ) { - return automaton.accessComponent < automaton::PushdownStoreAlphabet > ( ).get ( ).count ( symbol ); - } - - static void valid ( const automaton::DPDA &, const alphabet::Symbol & ) { - } -}; - -template < > -class ComponentConstraint2< automaton::DPDA, automaton::State, automaton::States > { -public: - static bool used ( const automaton::DPDA & automaton, const automaton::State & state ) { - if ( automaton.getInitialState ( ) == state ) - return true; - - if ( automaton.getFinalStates ( ).count ( state ) ) - return true; - - for (const std::pair<const std::tuple<automaton::State, std::variant<::string::Epsilon, alphabet::Symbol>, std::vector<alphabet::Symbol> >, std::pair<automaton::State, std::vector<alphabet::Symbol> > >& transition : automaton.getTransitions()) - if ( state == std::get<0>(transition.first) || transition.second.first == state ) - return true; - - return false; - } - - static bool available ( const automaton::DPDA &, const automaton::State & ) { - return true; - } - - static void valid ( const automaton::DPDA &, const automaton::State & ) { - } -}; - -template < > -class ComponentConstraint2< automaton::DPDA, automaton::State, automaton::FinalStates > { -public: - static bool used ( const automaton::DPDA &, const automaton::State & ) { - return false; - } - - static bool available ( const automaton::DPDA & automaton, const automaton::State & state ) { - return automaton.accessComponent < automaton::States > ( ).get ( ).count ( state ); - } - - static void valid ( const automaton::DPDA &, const automaton::State & ) { - } -}; - -template < > -class ElementConstraint2< automaton::DPDA, automaton::State, automaton::InitialState > { -public: - static bool available ( const automaton::DPDA & automaton, const automaton::State & state ) { - return automaton.accessComponent < automaton::States > ( ).get ( ).count ( state ); - } - - static void valid ( const automaton::DPDA &, const automaton::State & ) { - } -}; - -} /* namespace std */ - namespace alib { auto DPDAParserRegister = xmlApi<automaton::Automaton>::ParserRegister<automaton::DPDA>(); diff --git a/alib2data/src/automaton/PDA/DPDA.h b/alib2data/src/automaton/PDA/DPDA.h index 39d0b847200128889d706a56dfe684fefe647d8d..021bdb0b43f3432ca0ea3b5492d4b457aac7b575 100644 --- a/alib2data/src/automaton/PDA/DPDA.h +++ b/alib2data/src/automaton/PDA/DPDA.h @@ -8,6 +8,7 @@ #ifndef DPDA_H_ #define DPDA_H_ +#include "../AutomatonException.h" #include <set> #include <map> #include <vector> @@ -199,4 +200,114 @@ public: } /* namespace automaton */ +namespace std { + +template < > +class ComponentConstraint2< automaton::DPDA, alphabet::Symbol, automaton::InputAlphabet > { +public: + static bool used ( const automaton::DPDA & automaton, const alphabet::Symbol & symbol ) { + for (const std::pair<const std::tuple<automaton::State, std::variant<::string::Epsilon, alphabet::Symbol>, std::vector<alphabet::Symbol> >, std::pair<automaton::State, std::vector<alphabet::Symbol> > >& transition : automaton.getTransitions()) + if (std::get<1>(transition.first).is<alphabet::Symbol>() && symbol == std::get<1>(transition.first).get<alphabet::Symbol>()) + return true; + + return false; + } + + static bool available ( const automaton::DPDA &, const alphabet::Symbol & ) { + return true; + } + + static void valid ( const automaton::DPDA &, const alphabet::Symbol & ) { + } +}; + +template < > +class ComponentConstraint2< automaton::DPDA, alphabet::Symbol, automaton::PushdownStoreAlphabet > { +public: + static bool used ( const automaton::DPDA & automaton, const alphabet::Symbol & symbol ) { + if(automaton.getInitialSymbol() == symbol) + return true; + + for (const std::pair<const std::tuple<automaton::State, std::variant<::string::Epsilon, alphabet::Symbol>, std::vector<alphabet::Symbol> >, std::pair<automaton::State, std::vector<alphabet::Symbol> > >& transition : automaton.getTransitions()) { + const auto & popSymbols = std::get<2>(transition.first); + const auto & pushSymbols = transition.second.second; + if(std::contains(popSymbols.begin(), popSymbols.end(), symbol ) || std::contains(pushSymbols.begin(), pushSymbols.end(), symbol)) + return true; + } + + return false; + } + + static bool available ( const automaton::DPDA &, const alphabet::Symbol & ) { + return true; + } + + static void valid ( const automaton::DPDA &, const alphabet::Symbol & ) { + } +}; + +template < > +class ElementConstraint2< automaton::DPDA, alphabet::Symbol, automaton::InitialSymbol > { +public: + static bool available ( const automaton::DPDA & automaton, const alphabet::Symbol & symbol ) { + return automaton.accessComponent < automaton::PushdownStoreAlphabet > ( ).get ( ).count ( symbol ); + } + + static void valid ( const automaton::DPDA &, const alphabet::Symbol & ) { + } +}; + +template < > +class ComponentConstraint2< automaton::DPDA, automaton::State, automaton::States > { +public: + static bool used ( const automaton::DPDA & automaton, const automaton::State & state ) { + if ( automaton.getInitialState ( ) == state ) + return true; + + if ( automaton.getFinalStates ( ).count ( state ) ) + return true; + + for (const std::pair<const std::tuple<automaton::State, std::variant<::string::Epsilon, alphabet::Symbol>, std::vector<alphabet::Symbol> >, std::pair<automaton::State, std::vector<alphabet::Symbol> > >& transition : automaton.getTransitions()) + if ( state == std::get<0>(transition.first) || transition.second.first == state ) + return true; + + return false; + } + + static bool available ( const automaton::DPDA &, const automaton::State & ) { + return true; + } + + static void valid ( const automaton::DPDA &, const automaton::State & ) { + } +}; + +template < > +class ComponentConstraint2< automaton::DPDA, automaton::State, automaton::FinalStates > { +public: + static bool used ( const automaton::DPDA &, const automaton::State & ) { + return false; + } + + static bool available ( const automaton::DPDA & automaton, const automaton::State & state ) { + return automaton.accessComponent < automaton::States > ( ).get ( ).count ( state ); + } + + static void valid ( const automaton::DPDA &, const automaton::State & ) { + } +}; + +template < > +class ElementConstraint2< automaton::DPDA, automaton::State, automaton::InitialState > { +public: + static bool available ( const automaton::DPDA & automaton, const automaton::State & state ) { + return automaton.accessComponent < automaton::States > ( ).get ( ).count ( state ); + } + + static void valid ( const automaton::DPDA &, const automaton::State & ) { + } +}; + +} /* namespace std */ + #endif /* DPDA_H_ */ diff --git a/alib2data/src/automaton/PDA/InputDrivenDPDA.cpp b/alib2data/src/automaton/PDA/InputDrivenDPDA.cpp index de733fa3a57032ce1f4d64a327c8ceacac07faf3..bed763e973ce1b6aeb89c7b21eca8191c7914111 100644 --- a/alib2data/src/automaton/PDA/InputDrivenDPDA.cpp +++ b/alib2data/src/automaton/PDA/InputDrivenDPDA.cpp @@ -6,7 +6,6 @@ */ #include "InputDrivenDPDA.h" -#include "../AutomatonException.h" #include <ostream> #include <sstream> #include <algorithm> @@ -248,116 +247,6 @@ void InputDrivenDPDA::composeTransitions(std::deque<sax::Token>& out) const { } /* namespace automaton */ -namespace std { - -template < > -class ComponentConstraint2< automaton::InputDrivenDPDA, alphabet::Symbol, automaton::InputAlphabet > { -public: - static bool used ( const automaton::InputDrivenDPDA & automaton, const alphabet::Symbol & symbol ) { - for (const std::pair<const std::pair<automaton::State, alphabet::Symbol>, automaton::State>& transition : automaton.getTransitions()) - if (transition.first.second == symbol) - return true; - - return false; - } - - static bool available ( const automaton::InputDrivenDPDA &, const alphabet::Symbol & ) { - return true; - } - - static void valid ( const automaton::InputDrivenDPDA &, const alphabet::Symbol & ) { - } -}; - -template < > -class ComponentConstraint2< automaton::InputDrivenDPDA, alphabet::Symbol, automaton::PushdownStoreAlphabet > { -public: - static bool used ( const automaton::InputDrivenDPDA & automaton, const alphabet::Symbol & symbol ) { - for (const auto& pushdownStoreOperation : automaton.getPushdownStoreOperations()) { - if (std::find(pushdownStoreOperation.second.first.begin(), pushdownStoreOperation.second.first.end(), symbol) != pushdownStoreOperation.second.first.end()) - return true; - if (std::find(pushdownStoreOperation.second.second.begin(), pushdownStoreOperation.second.second.end(), symbol) != pushdownStoreOperation.second.second.end()) - return true; - } - - if(automaton.getInitialSymbol() == symbol) - return true; - - return false; - } - - static bool available ( const automaton::InputDrivenDPDA &, const alphabet::Symbol & ) { - return true; - } - - static void valid ( const automaton::InputDrivenDPDA &, const alphabet::Symbol & ) { - } -}; - -template < > -class ElementConstraint2< automaton::InputDrivenDPDA, alphabet::Symbol, automaton::InitialSymbol > { -public: - static bool available ( const automaton::InputDrivenDPDA & automaton, const alphabet::Symbol & symbol ) { - return automaton.accessComponent < automaton::PushdownStoreAlphabet > ( ).get ( ).count ( symbol ); - } - - static void valid ( const automaton::InputDrivenDPDA &, const alphabet::Symbol & ) { - } -}; - -template < > -class ComponentConstraint2< automaton::InputDrivenDPDA, automaton::State, automaton::States > { -public: - static bool used ( const automaton::InputDrivenDPDA & automaton, const automaton::State & state ) { - if ( automaton.getInitialState ( ) == state ) - return true; - - if ( automaton.getFinalStates ( ).count ( state ) ) - return true; - - for (const std::pair<const std::pair<automaton::State, alphabet::Symbol>, automaton::State>& t : automaton.getTransitions()) - if (t.first.first == state || t.second == state) - return true; - - return false; - } - - static bool available ( const automaton::InputDrivenDPDA &, const automaton::State & ) { - return true; - } - - static void valid ( const automaton::InputDrivenDPDA &, const automaton::State & ) { - } -}; - -template < > -class ComponentConstraint2< automaton::InputDrivenDPDA, automaton::State, automaton::FinalStates > { -public: - static bool used ( const automaton::InputDrivenDPDA &, const automaton::State & ) { - return false; - } - - static bool available ( const automaton::InputDrivenDPDA & automaton, const automaton::State & state ) { - return automaton.accessComponent < automaton::States > ( ).get ( ).count ( state ); - } - - static void valid ( const automaton::InputDrivenDPDA &, const automaton::State & ) { - } -}; - -template < > -class ElementConstraint2< automaton::InputDrivenDPDA, automaton::State, automaton::InitialState > { -public: - static bool available ( const automaton::InputDrivenDPDA & automaton, const automaton::State & state ) { - return automaton.accessComponent < automaton::States > ( ).get ( ).count ( state ); - } - - static void valid ( const automaton::InputDrivenDPDA &, const automaton::State & ) { - } -}; - -} /* namespace std */ - namespace alib { auto inputDivenDPDAParserRegister = xmlApi<automaton::Automaton>::ParserRegister<automaton::InputDrivenDPDA>(); diff --git a/alib2data/src/automaton/PDA/InputDrivenDPDA.h b/alib2data/src/automaton/PDA/InputDrivenDPDA.h index 45b15a91ccbd1c39188010d6bc38acae6611d31d..2584a7c9ca3ae48a81cc4a03d9cd41f58ff6ccd5 100644 --- a/alib2data/src/automaton/PDA/InputDrivenDPDA.h +++ b/alib2data/src/automaton/PDA/InputDrivenDPDA.h @@ -8,6 +8,7 @@ #ifndef INPUT_DRIVEN_DPDA_H_ #define INPUT_DRIVEN_DPDA_H_ +#include "../AutomatonException.h" #include <map> #include <vector> #include <core/components2.hpp> @@ -201,4 +202,114 @@ public: } /* namespace automaton */ +namespace std { + +template < > +class ComponentConstraint2< automaton::InputDrivenDPDA, alphabet::Symbol, automaton::InputAlphabet > { +public: + static bool used ( const automaton::InputDrivenDPDA & automaton, const alphabet::Symbol & symbol ) { + for (const std::pair<const std::pair<automaton::State, alphabet::Symbol>, automaton::State>& transition : automaton.getTransitions()) + if (transition.first.second == symbol) + return true; + + return false; + } + + static bool available ( const automaton::InputDrivenDPDA &, const alphabet::Symbol & ) { + return true; + } + + static void valid ( const automaton::InputDrivenDPDA &, const alphabet::Symbol & ) { + } +}; + +template < > +class ComponentConstraint2< automaton::InputDrivenDPDA, alphabet::Symbol, automaton::PushdownStoreAlphabet > { +public: + static bool used ( const automaton::InputDrivenDPDA & automaton, const alphabet::Symbol & symbol ) { + for (const auto& pushdownStoreOperation : automaton.getPushdownStoreOperations()) { + if (std::find(pushdownStoreOperation.second.first.begin(), pushdownStoreOperation.second.first.end(), symbol) != pushdownStoreOperation.second.first.end()) + return true; + if (std::find(pushdownStoreOperation.second.second.begin(), pushdownStoreOperation.second.second.end(), symbol) != pushdownStoreOperation.second.second.end()) + return true; + } + + if(automaton.getInitialSymbol() == symbol) + return true; + + return false; + } + + static bool available ( const automaton::InputDrivenDPDA &, const alphabet::Symbol & ) { + return true; + } + + static void valid ( const automaton::InputDrivenDPDA &, const alphabet::Symbol & ) { + } +}; + +template < > +class ElementConstraint2< automaton::InputDrivenDPDA, alphabet::Symbol, automaton::InitialSymbol > { +public: + static bool available ( const automaton::InputDrivenDPDA & automaton, const alphabet::Symbol & symbol ) { + return automaton.accessComponent < automaton::PushdownStoreAlphabet > ( ).get ( ).count ( symbol ); + } + + static void valid ( const automaton::InputDrivenDPDA &, const alphabet::Symbol & ) { + } +}; + +template < > +class ComponentConstraint2< automaton::InputDrivenDPDA, automaton::State, automaton::States > { +public: + static bool used ( const automaton::InputDrivenDPDA & automaton, const automaton::State & state ) { + if ( automaton.getInitialState ( ) == state ) + return true; + + if ( automaton.getFinalStates ( ).count ( state ) ) + return true; + + for (const std::pair<const std::pair<automaton::State, alphabet::Symbol>, automaton::State>& t : automaton.getTransitions()) + if (t.first.first == state || t.second == state) + return true; + + return false; + } + + static bool available ( const automaton::InputDrivenDPDA &, const automaton::State & ) { + return true; + } + + static void valid ( const automaton::InputDrivenDPDA &, const automaton::State & ) { + } +}; + +template < > +class ComponentConstraint2< automaton::InputDrivenDPDA, automaton::State, automaton::FinalStates > { +public: + static bool used ( const automaton::InputDrivenDPDA &, const automaton::State & ) { + return false; + } + + static bool available ( const automaton::InputDrivenDPDA & automaton, const automaton::State & state ) { + return automaton.accessComponent < automaton::States > ( ).get ( ).count ( state ); + } + + static void valid ( const automaton::InputDrivenDPDA &, const automaton::State & ) { + } +}; + +template < > +class ElementConstraint2< automaton::InputDrivenDPDA, automaton::State, automaton::InitialState > { +public: + static bool available ( const automaton::InputDrivenDPDA & automaton, const automaton::State & state ) { + return automaton.accessComponent < automaton::States > ( ).get ( ).count ( state ); + } + + static void valid ( const automaton::InputDrivenDPDA &, const automaton::State & ) { + } +}; + +} /* namespace std */ + #endif /* INPUT_DRIVEN_DPDA_H_ */ diff --git a/alib2data/src/automaton/PDA/InputDrivenNPDA.cpp b/alib2data/src/automaton/PDA/InputDrivenNPDA.cpp index 2ebd78b3d8465a221bca94a01f0c64b8790d5c5a..abd4b6f1d01b9b7d01256a794cd3f34d38c1e72c 100644 --- a/alib2data/src/automaton/PDA/InputDrivenNPDA.cpp +++ b/alib2data/src/automaton/PDA/InputDrivenNPDA.cpp @@ -6,7 +6,6 @@ */ #include "InputDrivenNPDA.h" -#include "../AutomatonException.h" #include <ostream> #include <sstream> #include <algorithm> @@ -245,116 +244,6 @@ void InputDrivenNPDA::composeTransitions(std::deque<sax::Token>& out) const { } /* namespace automaton */ -namespace std { - -template < > -class ComponentConstraint2< automaton::InputDrivenNPDA, alphabet::Symbol, automaton::InputAlphabet > { -public: - static bool used ( const automaton::InputDrivenNPDA & automaton, const alphabet::Symbol & symbol ) { - for (const std::pair<const std::pair<automaton::State, alphabet::Symbol>, std::set<automaton::State>>& transition : automaton.getTransitions()) - if (transition.first.second == symbol) - return true; - - return false; - } - - static bool available ( const automaton::InputDrivenNPDA &, const alphabet::Symbol & ) { - return true; - } - - static void valid ( const automaton::InputDrivenNPDA &, const alphabet::Symbol & ) { - } -}; - -template < > -class ComponentConstraint2< automaton::InputDrivenNPDA, alphabet::Symbol, automaton::PushdownStoreAlphabet > { -public: - static bool used ( const automaton::InputDrivenNPDA & automaton, const alphabet::Symbol & symbol ) { - for (const auto& pushdownStoreOperation : automaton.getPushdownStoreOperations()) { - if (std::find(pushdownStoreOperation.second.first.begin(), pushdownStoreOperation.second.first.end(), symbol) != pushdownStoreOperation.second.first.end()) - return true; - if (std::find(pushdownStoreOperation.second.second.begin(), pushdownStoreOperation.second.second.end(), symbol) != pushdownStoreOperation.second.second.end()) - return true; - } - - if(automaton.getInitialSymbol() == symbol) - return true; - - return false; - } - - static bool available ( const automaton::InputDrivenNPDA &, const alphabet::Symbol & ) { - return true; - } - - static void valid ( const automaton::InputDrivenNPDA &, const alphabet::Symbol & ) { - } -}; - -template < > -class ElementConstraint2< automaton::InputDrivenNPDA, alphabet::Symbol, automaton::InitialSymbol > { -public: - static bool available ( const automaton::InputDrivenNPDA & automaton, const alphabet::Symbol & symbol ) { - return automaton.accessComponent < automaton::PushdownStoreAlphabet > ( ).get ( ).count ( symbol ); - } - - static void valid ( const automaton::InputDrivenNPDA &, const alphabet::Symbol & ) { - } -}; - -template < > -class ComponentConstraint2< automaton::InputDrivenNPDA, automaton::State, automaton::States > { -public: - static bool used ( const automaton::InputDrivenNPDA & automaton, const automaton::State & state ) { - if ( automaton.getInitialState ( ) == state ) - return true; - - if ( automaton.getFinalStates ( ).count ( state ) ) - return true; - - for (const std::pair<const std::pair<automaton::State, alphabet::Symbol>, std::set<automaton::State> >& transition : automaton.getTransitions()) - if (transition.first.first == state || transition.second.find(state) != transition.second.end()) - return true; - - return false; - } - - static bool available ( const automaton::InputDrivenNPDA &, const automaton::State & ) { - return true; - } - - static void valid ( const automaton::InputDrivenNPDA &, const automaton::State & ) { - } -}; - -template < > -class ComponentConstraint2< automaton::InputDrivenNPDA, automaton::State, automaton::FinalStates > { -public: - static bool used ( const automaton::InputDrivenNPDA &, const automaton::State & ) { - return false; - } - - static bool available ( const automaton::InputDrivenNPDA & automaton, const automaton::State & state ) { - return automaton.accessComponent < automaton::States > ( ).get ( ).count ( state ); - } - - static void valid ( const automaton::InputDrivenNPDA &, const automaton::State & ) { - } -}; - -template < > -class ElementConstraint2< automaton::InputDrivenNPDA, automaton::State, automaton::InitialState > { -public: - static bool available ( const automaton::InputDrivenNPDA & automaton, const automaton::State & state ) { - return automaton.accessComponent < automaton::States > ( ).get ( ).count ( state ); - } - - static void valid ( const automaton::InputDrivenNPDA &, const automaton::State & ) { - } -}; - -} /* namespace std */ - namespace alib { auto inputDrivenNPDAParserRegister = xmlApi<automaton::Automaton>::ParserRegister<automaton::InputDrivenNPDA>(); diff --git a/alib2data/src/automaton/PDA/InputDrivenNPDA.h b/alib2data/src/automaton/PDA/InputDrivenNPDA.h index 6cb1609f779fca6b09156882ee26de8ebd6ef8cc..393ebc8e7c5d05bb1c5a097f0958ab421b1a1bca 100644 --- a/alib2data/src/automaton/PDA/InputDrivenNPDA.h +++ b/alib2data/src/automaton/PDA/InputDrivenNPDA.h @@ -8,6 +8,7 @@ #ifndef INPUT_DRIVEN_NPDA_H_ #define INPUT_DRIVEN_NPDA_H_ +#include "../AutomatonException.h" #include <map> #include <vector> #include <core/components2.hpp> @@ -201,4 +202,114 @@ public: } /* namespace automaton */ +namespace std { + +template < > +class ComponentConstraint2< automaton::InputDrivenNPDA, alphabet::Symbol, automaton::InputAlphabet > { +public: + static bool used ( const automaton::InputDrivenNPDA & automaton, const alphabet::Symbol & symbol ) { + for (const std::pair<const std::pair<automaton::State, alphabet::Symbol>, std::set<automaton::State>>& transition : automaton.getTransitions()) + if (transition.first.second == symbol) + return true; + + return false; + } + + static bool available ( const automaton::InputDrivenNPDA &, const alphabet::Symbol & ) { + return true; + } + + static void valid ( const automaton::InputDrivenNPDA &, const alphabet::Symbol & ) { + } +}; + +template < > +class ComponentConstraint2< automaton::InputDrivenNPDA, alphabet::Symbol, automaton::PushdownStoreAlphabet > { +public: + static bool used ( const automaton::InputDrivenNPDA & automaton, const alphabet::Symbol & symbol ) { + for (const auto& pushdownStoreOperation : automaton.getPushdownStoreOperations()) { + if (std::find(pushdownStoreOperation.second.first.begin(), pushdownStoreOperation.second.first.end(), symbol) != pushdownStoreOperation.second.first.end()) + return true; + if (std::find(pushdownStoreOperation.second.second.begin(), pushdownStoreOperation.second.second.end(), symbol) != pushdownStoreOperation.second.second.end()) + return true; + } + + if(automaton.getInitialSymbol() == symbol) + return true; + + return false; + } + + static bool available ( const automaton::InputDrivenNPDA &, const alphabet::Symbol & ) { + return true; + } + + static void valid ( const automaton::InputDrivenNPDA &, const alphabet::Symbol & ) { + } +}; + +template < > +class ElementConstraint2< automaton::InputDrivenNPDA, alphabet::Symbol, automaton::InitialSymbol > { +public: + static bool available ( const automaton::InputDrivenNPDA & automaton, const alphabet::Symbol & symbol ) { + return automaton.accessComponent < automaton::PushdownStoreAlphabet > ( ).get ( ).count ( symbol ); + } + + static void valid ( const automaton::InputDrivenNPDA &, const alphabet::Symbol & ) { + } +}; + +template < > +class ComponentConstraint2< automaton::InputDrivenNPDA, automaton::State, automaton::States > { +public: + static bool used ( const automaton::InputDrivenNPDA & automaton, const automaton::State & state ) { + if ( automaton.getInitialState ( ) == state ) + return true; + + if ( automaton.getFinalStates ( ).count ( state ) ) + return true; + + for (const std::pair<const std::pair<automaton::State, alphabet::Symbol>, std::set<automaton::State> >& transition : automaton.getTransitions()) + if (transition.first.first == state || transition.second.find(state) != transition.second.end()) + return true; + + return false; + } + + static bool available ( const automaton::InputDrivenNPDA &, const automaton::State & ) { + return true; + } + + static void valid ( const automaton::InputDrivenNPDA &, const automaton::State & ) { + } +}; + +template < > +class ComponentConstraint2< automaton::InputDrivenNPDA, automaton::State, automaton::FinalStates > { +public: + static bool used ( const automaton::InputDrivenNPDA &, const automaton::State & ) { + return false; + } + + static bool available ( const automaton::InputDrivenNPDA & automaton, const automaton::State & state ) { + return automaton.accessComponent < automaton::States > ( ).get ( ).count ( state ); + } + + static void valid ( const automaton::InputDrivenNPDA &, const automaton::State & ) { + } +}; + +template < > +class ElementConstraint2< automaton::InputDrivenNPDA, automaton::State, automaton::InitialState > { +public: + static bool available ( const automaton::InputDrivenNPDA & automaton, const automaton::State & state ) { + return automaton.accessComponent < automaton::States > ( ).get ( ).count ( state ); + } + + static void valid ( const automaton::InputDrivenNPDA &, const automaton::State & ) { + } +}; + +} /* namespace std */ + #endif /* INPUT_DRIVEN_NPDA_H_ */ diff --git a/alib2data/src/automaton/PDA/NPDA.cpp b/alib2data/src/automaton/PDA/NPDA.cpp index e5dbda5f32e42b15042dabe74a01ec9a2ba72e3e..c847bb3a7210bc564232eb51705ff7e5fa5b176c 100644 --- a/alib2data/src/automaton/PDA/NPDA.cpp +++ b/alib2data/src/automaton/PDA/NPDA.cpp @@ -6,7 +6,6 @@ */ #include "NPDA.h" -#include "../AutomatonException.h" #include <algorithm> #include <sstream> @@ -184,123 +183,6 @@ void NPDA::composeTransitions(std::deque<sax::Token>& out) const { } /* namespace automaton */ -namespace std { - -template < > -class ComponentConstraint2< automaton::NPDA, alphabet::Symbol, automaton::InputAlphabet > { -public: - static bool used ( const automaton::NPDA & automaton, const alphabet::Symbol & symbol ) { - for (const std::pair<const std::tuple<automaton::State, std::variant<::string::Epsilon, alphabet::Symbol>, std::vector<alphabet::Symbol> >, std::set<std::pair<automaton::State, std::vector<alphabet::Symbol> > > >& transition : automaton.getTransitions()) - if (std::get<1>(transition.first).is<alphabet::Symbol>() && symbol == std::get<1>(transition.first).get<alphabet::Symbol>()) - return true; - - return false; - } - - static bool available ( const automaton::NPDA &, const alphabet::Symbol & ) { - return true; - } - - static void valid ( const automaton::NPDA &, const alphabet::Symbol & ) { - } -}; - -template < > -class ComponentConstraint2< automaton::NPDA, alphabet::Symbol, automaton::PushdownStoreAlphabet > { -public: - static bool used ( const automaton::NPDA & automaton, const alphabet::Symbol & symbol ) { - if(automaton.getInitialSymbol() == symbol) - return true; - - for (const std::pair<const std::tuple<automaton::State, std::variant<::string::Epsilon, alphabet::Symbol>, std::vector<alphabet::Symbol> >, std::set<std::pair<automaton::State, std::vector<alphabet::Symbol> > > >& transition : automaton.getTransitions()) { - for (const alphabet::Symbol& popSymbol : std::get<2>(transition.first)) - if (symbol == popSymbol) - return true; - - for (const std::pair<automaton::State, std::vector<alphabet::Symbol> >& target : transition.second) - if (std::find(target.second.begin(), target.second.end(), symbol) != target.second.end()) - return true; - } - - return false; - } - - static bool available ( const automaton::NPDA &, const alphabet::Symbol & ) { - return true; - } - - static void valid ( const automaton::NPDA &, const alphabet::Symbol & ) { - } -}; - -template < > -class ElementConstraint2< automaton::NPDA, alphabet::Symbol, automaton::InitialSymbol > { -public: - static bool available ( const automaton::NPDA & automaton, const alphabet::Symbol & symbol ) { - return automaton.accessComponent < automaton::PushdownStoreAlphabet > ( ).get ( ).count ( symbol ); - } - - static void valid ( const automaton::NPDA &, const alphabet::Symbol & ) { - } -}; - -template < > -class ComponentConstraint2< automaton::NPDA, automaton::State, automaton::States > { -public: - static bool used ( const automaton::NPDA & automaton, const automaton::State & state ) { - if ( automaton.getInitialState ( ) == state ) - return true; - - if ( automaton.getFinalStates ( ).count ( state ) ) - return true; - - for (const std::pair<const std::tuple<automaton::State, std::variant<::string::Epsilon, alphabet::Symbol>, std::vector<alphabet::Symbol> >, std::set<std::pair<automaton::State, std::vector<alphabet::Symbol> > > >& transition : automaton.getTransitions()) { - if (state == std::get<0>(transition.first)) - return true; - for(const std::pair<automaton::State, std::vector<alphabet::Symbol> >& target : transition.second) - if(target.first == state) - return true; - } - - return false; - } - - static bool available ( const automaton::NPDA &, const automaton::State & ) { - return true; - } - - static void valid ( const automaton::NPDA &, const automaton::State & ) { - } -}; - -template < > -class ComponentConstraint2< automaton::NPDA, automaton::State, automaton::FinalStates > { -public: - static bool used ( const automaton::NPDA &, const automaton::State & ) { - return false; - } - - static bool available ( const automaton::NPDA & automaton, const automaton::State & state ) { - return automaton.accessComponent < automaton::States > ( ).get ( ).count ( state ); - } - - static void valid ( const automaton::NPDA &, const automaton::State & ) { - } -}; - -template < > -class ElementConstraint2< automaton::NPDA, automaton::State, automaton::InitialState > { -public: - static bool available ( const automaton::NPDA & automaton, const automaton::State & state ) { - return automaton.accessComponent < automaton::States > ( ).get ( ).count ( state ); - } - - static void valid ( const automaton::NPDA &, const automaton::State & ) { - } -}; - -} /* namespace std */ - namespace alib { auto NPDAParserRegister = xmlApi<automaton::Automaton>::ParserRegister<automaton::NPDA>(); diff --git a/alib2data/src/automaton/PDA/NPDA.h b/alib2data/src/automaton/PDA/NPDA.h index 4ad36c2696610d7501c9cff0a8bded0c1b9ebd32..7f44a8bcdc567974a97895d01743a1000b37a59d 100644 --- a/alib2data/src/automaton/PDA/NPDA.h +++ b/alib2data/src/automaton/PDA/NPDA.h @@ -8,6 +8,7 @@ #ifndef NPDA_H_ #define NPDA_H_ +#include "../AutomatonException.h" #include <set> #include <map> #include <vector> @@ -185,4 +186,121 @@ public: } /* namespace automaton */ +namespace std { + +template < > +class ComponentConstraint2< automaton::NPDA, alphabet::Symbol, automaton::InputAlphabet > { +public: + static bool used ( const automaton::NPDA & automaton, const alphabet::Symbol & symbol ) { + for (const std::pair<const std::tuple<automaton::State, std::variant<::string::Epsilon, alphabet::Symbol>, std::vector<alphabet::Symbol> >, std::set<std::pair<automaton::State, std::vector<alphabet::Symbol> > > >& transition : automaton.getTransitions()) + if (std::get<1>(transition.first).is<alphabet::Symbol>() && symbol == std::get<1>(transition.first).get<alphabet::Symbol>()) + return true; + + return false; + } + + static bool available ( const automaton::NPDA &, const alphabet::Symbol & ) { + return true; + } + + static void valid ( const automaton::NPDA &, const alphabet::Symbol & ) { + } +}; + +template < > +class ComponentConstraint2< automaton::NPDA, alphabet::Symbol, automaton::PushdownStoreAlphabet > { +public: + static bool used ( const automaton::NPDA & automaton, const alphabet::Symbol & symbol ) { + if(automaton.getInitialSymbol() == symbol) + return true; + + for (const std::pair<const std::tuple<automaton::State, std::variant<::string::Epsilon, alphabet::Symbol>, std::vector<alphabet::Symbol> >, std::set<std::pair<automaton::State, std::vector<alphabet::Symbol> > > >& transition : automaton.getTransitions()) { + for (const alphabet::Symbol& popSymbol : std::get<2>(transition.first)) + if (symbol == popSymbol) + return true; + + for (const std::pair<automaton::State, std::vector<alphabet::Symbol> >& target : transition.second) + if (std::find(target.second.begin(), target.second.end(), symbol) != target.second.end()) + return true; + } + + return false; + } + + static bool available ( const automaton::NPDA &, const alphabet::Symbol & ) { + return true; + } + + static void valid ( const automaton::NPDA &, const alphabet::Symbol & ) { + } +}; + +template < > +class ElementConstraint2< automaton::NPDA, alphabet::Symbol, automaton::InitialSymbol > { +public: + static bool available ( const automaton::NPDA & automaton, const alphabet::Symbol & symbol ) { + return automaton.accessComponent < automaton::PushdownStoreAlphabet > ( ).get ( ).count ( symbol ); + } + + static void valid ( const automaton::NPDA &, const alphabet::Symbol & ) { + } +}; + +template < > +class ComponentConstraint2< automaton::NPDA, automaton::State, automaton::States > { +public: + static bool used ( const automaton::NPDA & automaton, const automaton::State & state ) { + if ( automaton.getInitialState ( ) == state ) + return true; + + if ( automaton.getFinalStates ( ).count ( state ) ) + return true; + + for (const std::pair<const std::tuple<automaton::State, std::variant<::string::Epsilon, alphabet::Symbol>, std::vector<alphabet::Symbol> >, std::set<std::pair<automaton::State, std::vector<alphabet::Symbol> > > >& transition : automaton.getTransitions()) { + if (state == std::get<0>(transition.first)) + return true; + for(const std::pair<automaton::State, std::vector<alphabet::Symbol> >& target : transition.second) + if(target.first == state) + return true; + } + + return false; + } + + static bool available ( const automaton::NPDA &, const automaton::State & ) { + return true; + } + + static void valid ( const automaton::NPDA &, const automaton::State & ) { + } +}; + +template < > +class ComponentConstraint2< automaton::NPDA, automaton::State, automaton::FinalStates > { +public: + static bool used ( const automaton::NPDA &, const automaton::State & ) { + return false; + } + + static bool available ( const automaton::NPDA & automaton, const automaton::State & state ) { + return automaton.accessComponent < automaton::States > ( ).get ( ).count ( state ); + } + + static void valid ( const automaton::NPDA &, const automaton::State & ) { + } +}; + +template < > +class ElementConstraint2< automaton::NPDA, automaton::State, automaton::InitialState > { +public: + static bool available ( const automaton::NPDA & automaton, const automaton::State & state ) { + return automaton.accessComponent < automaton::States > ( ).get ( ).count ( state ); + } + + static void valid ( const automaton::NPDA &, const automaton::State & ) { + } +}; + +} /* namespace std */ + #endif /* NPDA_H_ */ diff --git a/alib2data/src/automaton/PDA/NPDTA.cpp b/alib2data/src/automaton/PDA/NPDTA.cpp index 632ec9510ae5ed003653970b2cd6718af61809f9..852b47a2701267fb17277e21158e68a8909a2a70 100644 --- a/alib2data/src/automaton/PDA/NPDTA.cpp +++ b/alib2data/src/automaton/PDA/NPDTA.cpp @@ -6,7 +6,6 @@ */ #include "NPDTA.h" -#include "../AutomatonException.h" #include <algorithm> #include <sstream> @@ -219,144 +218,6 @@ void NPDTA::composeTransitions(std::deque<sax::Token>& out) const { } /* namespace automaton */ -namespace std { - -template < > -class ComponentConstraint2< automaton::NPDTA, alphabet::Symbol, automaton::InputAlphabet > { -public: - static bool used ( const automaton::NPDTA & automaton, const alphabet::Symbol & symbol ) { - for (const std::pair<const std::tuple<automaton::State, std::variant<::string::Epsilon, alphabet::Symbol>, std::vector<alphabet::Symbol> >, std::set<std::tuple<automaton::State, std::vector<alphabet::Symbol>, std::vector<alphabet::Symbol> > > >& transition : automaton.getTransitions()) - if (std::get<1>(transition.first).is<alphabet::Symbol>() && symbol == std::get<1>(transition.first).get<alphabet::Symbol>()) - return true; - - return false; - } - - static bool available ( const automaton::NPDTA &, const alphabet::Symbol & ) { - return true; - } - - static void valid ( const automaton::NPDTA &, const alphabet::Symbol & ) { - } -}; - -template < > -class ComponentConstraint2< automaton::NPDTA, alphabet::Symbol, automaton::OutputAlphabet > { -public: - static bool used ( const automaton::NPDTA & automaton, const alphabet::Symbol & symbol ) { - for (const std::pair<const std::tuple<automaton::State, std::variant<::string::Epsilon, alphabet::Symbol>, std::vector<alphabet::Symbol> >, std::set<std::tuple<automaton::State, std::vector<alphabet::Symbol>, std::vector<alphabet::Symbol> > > >& transition : automaton.getTransitions()) - for(const std::tuple<automaton::State, std::vector<alphabet::Symbol>, std::vector<alphabet::Symbol> >& target : transition.second) - if (std::find(std::get<2>(target).begin(), std::get<2>(target).end(), symbol) != std::get<2>(target).end()) - return true; - - return false; - } - - static bool available ( const automaton::NPDTA &, const alphabet::Symbol & ) { - return true; - } - - static void valid ( const automaton::NPDTA &, const alphabet::Symbol & ) { - } -}; - -template < > -class ComponentConstraint2< automaton::NPDTA, alphabet::Symbol, automaton::PushdownStoreAlphabet > { -public: - static bool used ( const automaton::NPDTA & automaton, const alphabet::Symbol & symbol ) { - if(automaton.getInitialSymbol() == symbol) - return true; - - for (const std::pair<const std::tuple<automaton::State, std::variant<::string::Epsilon, alphabet::Symbol>, std::vector<alphabet::Symbol> >, std::set<std::tuple<automaton::State, std::vector<alphabet::Symbol>, std::vector<alphabet::Symbol> > > >& transition : automaton.getTransitions()) { - for (const alphabet::Symbol& popSymbol : std::get<2>(transition.first)) - if (symbol == popSymbol) - return true; - - for (const std::tuple<automaton::State, std::vector<alphabet::Symbol>, std::vector<alphabet::Symbol> >& target : transition.second) - if (std::find(std::get<1>(target).begin(), std::get<1>(target).end(), symbol) != std::get<1>(target).end()) - return true; - } - - return false; - } - - static bool available ( const automaton::NPDTA &, const alphabet::Symbol & ) { - return true; - } - - static void valid ( const automaton::NPDTA &, const alphabet::Symbol & ) { - } -}; - -template < > -class ElementConstraint2< automaton::NPDTA, alphabet::Symbol, automaton::InitialSymbol > { -public: - static bool available ( const automaton::NPDTA & automaton, const alphabet::Symbol & symbol ) { - return automaton.accessComponent < automaton::PushdownStoreAlphabet > ( ).get ( ).count ( symbol ); - } - - static void valid ( const automaton::NPDTA &, const alphabet::Symbol & ) { - } -}; - -template < > -class ComponentConstraint2< automaton::NPDTA, automaton::State, automaton::States > { -public: - static bool used ( const automaton::NPDTA & automaton, const automaton::State & state ) { - if ( automaton.getInitialState ( ) == state ) - return true; - - if ( automaton.getFinalStates ( ).count ( state ) ) - return true; - - for (const std::pair<const std::tuple<automaton::State, std::variant<::string::Epsilon, alphabet::Symbol>, std::vector<alphabet::Symbol> >, std::set<std::tuple<automaton::State, std::vector<alphabet::Symbol>, std::vector<alphabet::Symbol> > > >& transition : automaton.getTransitions()) { - if (state == std::get<0>(transition.first)) - return true; - - for(const std::tuple<automaton::State, std::vector<alphabet::Symbol>, std::vector<alphabet::Symbol> >& target : transition.second) - if(std::get<0>(target) == state) - return true; - } - - return false; - } - - static bool available ( const automaton::NPDTA &, const automaton::State & ) { - return true; - } - - static void valid ( const automaton::NPDTA &, const automaton::State & ) { - } -}; - -template < > -class ComponentConstraint2< automaton::NPDTA, automaton::State, automaton::FinalStates > { -public: - static bool used ( const automaton::NPDTA &, const automaton::State & ) { - return false; - } - - static bool available ( const automaton::NPDTA & automaton, const automaton::State & state ) { - return automaton.accessComponent < automaton::States > ( ).get ( ).count ( state ); - } - - static void valid ( const automaton::NPDTA &, const automaton::State & ) { - } -}; - -template < > -class ElementConstraint2< automaton::NPDTA, automaton::State, automaton::InitialState > { -public: - static bool available ( const automaton::NPDTA & automaton, const automaton::State & state ) { - return automaton.accessComponent < automaton::States > ( ).get ( ).count ( state ); - } - - static void valid ( const automaton::NPDTA &, const automaton::State & ) { - } -}; - -} /* namespace std */ - namespace alib { auto NPDTAParserRegister = xmlApi<automaton::Automaton>::ParserRegister<automaton::NPDTA>(); diff --git a/alib2data/src/automaton/PDA/NPDTA.h b/alib2data/src/automaton/PDA/NPDTA.h index 9e3bbbcb7d1049c288dd6c0ba56175b6b164f648..224886688f74458cb9139a9fa187f29339423322 100644 --- a/alib2data/src/automaton/PDA/NPDTA.h +++ b/alib2data/src/automaton/PDA/NPDTA.h @@ -8,6 +8,7 @@ #ifndef NPDTA_H_ #define NPDTA_H_ +#include "../AutomatonException.h" #include <set> #include <map> #include <vector> @@ -209,4 +210,142 @@ public: } /* namespace automaton */ +namespace std { + +template < > +class ComponentConstraint2< automaton::NPDTA, alphabet::Symbol, automaton::InputAlphabet > { +public: + static bool used ( const automaton::NPDTA & automaton, const alphabet::Symbol & symbol ) { + for (const std::pair<const std::tuple<automaton::State, std::variant<::string::Epsilon, alphabet::Symbol>, std::vector<alphabet::Symbol> >, std::set<std::tuple<automaton::State, std::vector<alphabet::Symbol>, std::vector<alphabet::Symbol> > > >& transition : automaton.getTransitions()) + if (std::get<1>(transition.first).is<alphabet::Symbol>() && symbol == std::get<1>(transition.first).get<alphabet::Symbol>()) + return true; + + return false; + } + + static bool available ( const automaton::NPDTA &, const alphabet::Symbol & ) { + return true; + } + + static void valid ( const automaton::NPDTA &, const alphabet::Symbol & ) { + } +}; + +template < > +class ComponentConstraint2< automaton::NPDTA, alphabet::Symbol, automaton::OutputAlphabet > { +public: + static bool used ( const automaton::NPDTA & automaton, const alphabet::Symbol & symbol ) { + for (const std::pair<const std::tuple<automaton::State, std::variant<::string::Epsilon, alphabet::Symbol>, std::vector<alphabet::Symbol> >, std::set<std::tuple<automaton::State, std::vector<alphabet::Symbol>, std::vector<alphabet::Symbol> > > >& transition : automaton.getTransitions()) + for(const std::tuple<automaton::State, std::vector<alphabet::Symbol>, std::vector<alphabet::Symbol> >& target : transition.second) + if (std::find(std::get<2>(target).begin(), std::get<2>(target).end(), symbol) != std::get<2>(target).end()) + return true; + + return false; + } + + static bool available ( const automaton::NPDTA &, const alphabet::Symbol & ) { + return true; + } + + static void valid ( const automaton::NPDTA &, const alphabet::Symbol & ) { + } +}; + +template < > +class ComponentConstraint2< automaton::NPDTA, alphabet::Symbol, automaton::PushdownStoreAlphabet > { +public: + static bool used ( const automaton::NPDTA & automaton, const alphabet::Symbol & symbol ) { + if(automaton.getInitialSymbol() == symbol) + return true; + + for (const std::pair<const std::tuple<automaton::State, std::variant<::string::Epsilon, alphabet::Symbol>, std::vector<alphabet::Symbol> >, std::set<std::tuple<automaton::State, std::vector<alphabet::Symbol>, std::vector<alphabet::Symbol> > > >& transition : automaton.getTransitions()) { + for (const alphabet::Symbol& popSymbol : std::get<2>(transition.first)) + if (symbol == popSymbol) + return true; + + for (const std::tuple<automaton::State, std::vector<alphabet::Symbol>, std::vector<alphabet::Symbol> >& target : transition.second) + if (std::find(std::get<1>(target).begin(), std::get<1>(target).end(), symbol) != std::get<1>(target).end()) + return true; + } + + return false; + } + + static bool available ( const automaton::NPDTA &, const alphabet::Symbol & ) { + return true; + } + + static void valid ( const automaton::NPDTA &, const alphabet::Symbol & ) { + } +}; + +template < > +class ElementConstraint2< automaton::NPDTA, alphabet::Symbol, automaton::InitialSymbol > { +public: + static bool available ( const automaton::NPDTA & automaton, const alphabet::Symbol & symbol ) { + return automaton.accessComponent < automaton::PushdownStoreAlphabet > ( ).get ( ).count ( symbol ); + } + + static void valid ( const automaton::NPDTA &, const alphabet::Symbol & ) { + } +}; + +template < > +class ComponentConstraint2< automaton::NPDTA, automaton::State, automaton::States > { +public: + static bool used ( const automaton::NPDTA & automaton, const automaton::State & state ) { + if ( automaton.getInitialState ( ) == state ) + return true; + + if ( automaton.getFinalStates ( ).count ( state ) ) + return true; + + for (const std::pair<const std::tuple<automaton::State, std::variant<::string::Epsilon, alphabet::Symbol>, std::vector<alphabet::Symbol> >, std::set<std::tuple<automaton::State, std::vector<alphabet::Symbol>, std::vector<alphabet::Symbol> > > >& transition : automaton.getTransitions()) { + if (state == std::get<0>(transition.first)) + return true; + + for(const std::tuple<automaton::State, std::vector<alphabet::Symbol>, std::vector<alphabet::Symbol> >& target : transition.second) + if(std::get<0>(target) == state) + return true; + } + + return false; + } + + static bool available ( const automaton::NPDTA &, const automaton::State & ) { + return true; + } + + static void valid ( const automaton::NPDTA &, const automaton::State & ) { + } +}; + +template < > +class ComponentConstraint2< automaton::NPDTA, automaton::State, automaton::FinalStates > { +public: + static bool used ( const automaton::NPDTA &, const automaton::State & ) { + return false; + } + + static bool available ( const automaton::NPDTA & automaton, const automaton::State & state ) { + return automaton.accessComponent < automaton::States > ( ).get ( ).count ( state ); + } + + static void valid ( const automaton::NPDTA &, const automaton::State & ) { + } +}; + +template < > +class ElementConstraint2< automaton::NPDTA, automaton::State, automaton::InitialState > { +public: + static bool available ( const automaton::NPDTA & automaton, const automaton::State & state ) { + return automaton.accessComponent < automaton::States > ( ).get ( ).count ( state ); + } + + static void valid ( const automaton::NPDTA &, const automaton::State & ) { + } +}; + +} /* namespace std */ + #endif /* NPDTA_H_ */ diff --git a/alib2data/src/automaton/PDA/RealTimeHeightDeterministicDPDA.cpp b/alib2data/src/automaton/PDA/RealTimeHeightDeterministicDPDA.cpp index 0417a377362e96988224d2732fdf0963c1fa1fda..ca6199f3d7840932c911076feb1be55628b7cd7b 100644 --- a/alib2data/src/automaton/PDA/RealTimeHeightDeterministicDPDA.cpp +++ b/alib2data/src/automaton/PDA/RealTimeHeightDeterministicDPDA.cpp @@ -6,7 +6,6 @@ */ #include "RealTimeHeightDeterministicDPDA.h" -#include "../AutomatonException.h" #include <algorithm> #include <sstream> @@ -438,133 +437,6 @@ void RealTimeHeightDeterministicDPDA::composeTransitions(std::deque<sax::Token>& } /* namespace automaton */ -namespace std { - -template < > -class ComponentConstraint2< automaton::RealTimeHeightDeterministicDPDA, alphabet::Symbol, automaton::InputAlphabet > { -public: - static bool used ( const automaton::RealTimeHeightDeterministicDPDA & automaton, const alphabet::Symbol & symbol ) { - for (const std::pair<const std::pair<automaton::State, std::variant<::string::Epsilon, alphabet::Symbol>>, std::pair<automaton::State, alphabet::Symbol> >& callTransition : automaton.getCallTransitions()) - if (callTransition.first.second.is<alphabet::Symbol>() && symbol == callTransition.first.second.get<alphabet::Symbol>()) - return true; - - for (const std::pair<const std::tuple<automaton::State, std::variant<::string::Epsilon, alphabet::Symbol>, alphabet::Symbol>, automaton::State>& returnTransition : automaton.getReturnTransitions()) - if (std::get<1>(returnTransition.first).is<alphabet::Symbol>() && symbol == std::get<1>(returnTransition.first).get<alphabet::Symbol>()) - return true; - - for (const std::pair<const std::pair<automaton::State, std::variant<::string::Epsilon, alphabet::Symbol>>, automaton::State>& localTransition : automaton.getLocalTransitions()) - if (localTransition.first.second.is<alphabet::Symbol>() && symbol == localTransition.first.second.get<alphabet::Symbol>()) - return true; - - return false; - } - - static bool available ( const automaton::RealTimeHeightDeterministicDPDA &, const alphabet::Symbol & ) { - return true; - } - - static void valid ( const automaton::RealTimeHeightDeterministicDPDA &, const alphabet::Symbol & ) { - } -}; - -template < > -class ComponentConstraint2< automaton::RealTimeHeightDeterministicDPDA, alphabet::Symbol, automaton::PushdownStoreAlphabet > { -public: - static bool used ( const automaton::RealTimeHeightDeterministicDPDA & automaton, const alphabet::Symbol & symbol ) { - for (const std::pair<const std::pair<automaton::State, std::variant<::string::Epsilon, alphabet::Symbol>>, std::pair<automaton::State, alphabet::Symbol> >& callTransition : automaton.getCallTransitions()) - if (symbol == callTransition.second.second) - return true; - - for (const std::pair<const std::tuple<automaton::State, std::variant<::string::Epsilon, alphabet::Symbol>, alphabet::Symbol>, automaton::State>& returnTransition : automaton.getReturnTransitions()) - if (symbol == std::get<2>(returnTransition.first)) - return true; - - if(automaton.getBottomOfTheStackSymbol() == symbol) - return true; - - return false; - } - - static bool available ( const automaton::RealTimeHeightDeterministicDPDA &, const alphabet::Symbol & ) { - return true; - } - - static void valid ( const automaton::RealTimeHeightDeterministicDPDA &, const alphabet::Symbol & ) { - } -}; - -template < > -class ElementConstraint2< automaton::RealTimeHeightDeterministicDPDA, alphabet::Symbol, automaton::BottomOfTheStackSymbol > { -public: - static bool available ( const automaton::RealTimeHeightDeterministicDPDA & automaton, const alphabet::Symbol & symbol ) { - return automaton.accessComponent < automaton::PushdownStoreAlphabet > ( ).get ( ).count ( symbol ); - } - - static void valid ( const automaton::RealTimeHeightDeterministicDPDA &, const alphabet::Symbol & ) { - } -}; - -template < > -class ComponentConstraint2< automaton::RealTimeHeightDeterministicDPDA, automaton::State, automaton::States > { -public: - static bool used ( const automaton::RealTimeHeightDeterministicDPDA & automaton, const automaton::State & state ) { - if ( automaton.getInitialState ( ) == state ) - return true; - - if ( automaton.getFinalStates ( ).count ( state ) ) - return true; - - for (const std::pair<const std::pair<automaton::State, std::variant<::string::Epsilon, alphabet::Symbol>>, std::pair<automaton::State, alphabet::Symbol> >& callTransition : automaton.getCallTransitions()) - if (state == callTransition.first.first || callTransition.second.first == state) - return true; - - for (const std::pair<const std::tuple<automaton::State, std::variant<::string::Epsilon, alphabet::Symbol>, alphabet::Symbol>, automaton::State>& returnTransition : automaton.getReturnTransitions()) - if (state == std::get<0>(returnTransition.first) || returnTransition.second == state) - return true; - - for (const std::pair<const std::pair<automaton::State, std::variant<::string::Epsilon, alphabet::Symbol>>, automaton::State>& localTransition : automaton.getLocalTransitions()) - if (state == localTransition.first.first || localTransition.second == state) - return true; - - return false; - } - - static bool available ( const automaton::RealTimeHeightDeterministicDPDA &, const automaton::State & ) { - return true; - } - - static void valid ( const automaton::RealTimeHeightDeterministicDPDA &, const automaton::State & ) { - } -}; - -template < > -class ComponentConstraint2< automaton::RealTimeHeightDeterministicDPDA, automaton::State, automaton::FinalStates > { -public: - static bool used ( const automaton::RealTimeHeightDeterministicDPDA &, const automaton::State & ) { - return false; - } - - static bool available ( const automaton::RealTimeHeightDeterministicDPDA & automaton, const automaton::State & state ) { - return automaton.accessComponent < automaton::States > ( ).get ( ).count ( state ); - } - - static void valid ( const automaton::RealTimeHeightDeterministicDPDA &, const automaton::State & ) { - } -}; - -template < > -class ElementConstraint2< automaton::RealTimeHeightDeterministicDPDA, automaton::State, automaton::InitialState > { -public: - static bool available ( const automaton::RealTimeHeightDeterministicDPDA & automaton, const automaton::State & state ) { - return automaton.accessComponent < automaton::States > ( ).get ( ).count ( state ); - } - - static void valid ( const automaton::RealTimeHeightDeterministicDPDA &, const automaton::State & ) { - } -}; - -} /* namespace std */ - namespace alib { auto realTimeHeightDeterministicDPDAParserRegister = xmlApi<automaton::Automaton>::ParserRegister<automaton::RealTimeHeightDeterministicDPDA>(); diff --git a/alib2data/src/automaton/PDA/RealTimeHeightDeterministicDPDA.h b/alib2data/src/automaton/PDA/RealTimeHeightDeterministicDPDA.h index d5fd1cc627bb355f400f27e3e2809a41090f5ecc..99ea87d1fa415b64b8dd2e9c2a91906bf87c67ca 100644 --- a/alib2data/src/automaton/PDA/RealTimeHeightDeterministicDPDA.h +++ b/alib2data/src/automaton/PDA/RealTimeHeightDeterministicDPDA.h @@ -8,6 +8,7 @@ #ifndef REAL_TIME_HEIGHT_DETERMINISTIC_DPDA_H_ #define REAL_TIME_HEIGHT_DETERMINISTIC_DPDA_H_ +#include "../AutomatonException.h" #include <map> #include <vector> #include <variant> @@ -225,4 +226,131 @@ public: } /* namespace automaton */ +namespace std { + +template < > +class ComponentConstraint2< automaton::RealTimeHeightDeterministicDPDA, alphabet::Symbol, automaton::InputAlphabet > { +public: + static bool used ( const automaton::RealTimeHeightDeterministicDPDA & automaton, const alphabet::Symbol & symbol ) { + for (const std::pair<const std::pair<automaton::State, std::variant<::string::Epsilon, alphabet::Symbol>>, std::pair<automaton::State, alphabet::Symbol> >& callTransition : automaton.getCallTransitions()) + if (callTransition.first.second.is<alphabet::Symbol>() && symbol == callTransition.first.second.get<alphabet::Symbol>()) + return true; + + for (const std::pair<const std::tuple<automaton::State, std::variant<::string::Epsilon, alphabet::Symbol>, alphabet::Symbol>, automaton::State>& returnTransition : automaton.getReturnTransitions()) + if (std::get<1>(returnTransition.first).is<alphabet::Symbol>() && symbol == std::get<1>(returnTransition.first).get<alphabet::Symbol>()) + return true; + + for (const std::pair<const std::pair<automaton::State, std::variant<::string::Epsilon, alphabet::Symbol>>, automaton::State>& localTransition : automaton.getLocalTransitions()) + if (localTransition.first.second.is<alphabet::Symbol>() && symbol == localTransition.first.second.get<alphabet::Symbol>()) + return true; + + return false; + } + + static bool available ( const automaton::RealTimeHeightDeterministicDPDA &, const alphabet::Symbol & ) { + return true; + } + + static void valid ( const automaton::RealTimeHeightDeterministicDPDA &, const alphabet::Symbol & ) { + } +}; + +template < > +class ComponentConstraint2< automaton::RealTimeHeightDeterministicDPDA, alphabet::Symbol, automaton::PushdownStoreAlphabet > { +public: + static bool used ( const automaton::RealTimeHeightDeterministicDPDA & automaton, const alphabet::Symbol & symbol ) { + for (const std::pair<const std::pair<automaton::State, std::variant<::string::Epsilon, alphabet::Symbol>>, std::pair<automaton::State, alphabet::Symbol> >& callTransition : automaton.getCallTransitions()) + if (symbol == callTransition.second.second) + return true; + + for (const std::pair<const std::tuple<automaton::State, std::variant<::string::Epsilon, alphabet::Symbol>, alphabet::Symbol>, automaton::State>& returnTransition : automaton.getReturnTransitions()) + if (symbol == std::get<2>(returnTransition.first)) + return true; + + if(automaton.getBottomOfTheStackSymbol() == symbol) + return true; + + return false; + } + + static bool available ( const automaton::RealTimeHeightDeterministicDPDA &, const alphabet::Symbol & ) { + return true; + } + + static void valid ( const automaton::RealTimeHeightDeterministicDPDA &, const alphabet::Symbol & ) { + } +}; + +template < > +class ElementConstraint2< automaton::RealTimeHeightDeterministicDPDA, alphabet::Symbol, automaton::BottomOfTheStackSymbol > { +public: + static bool available ( const automaton::RealTimeHeightDeterministicDPDA & automaton, const alphabet::Symbol & symbol ) { + return automaton.accessComponent < automaton::PushdownStoreAlphabet > ( ).get ( ).count ( symbol ); + } + + static void valid ( const automaton::RealTimeHeightDeterministicDPDA &, const alphabet::Symbol & ) { + } +}; + +template < > +class ComponentConstraint2< automaton::RealTimeHeightDeterministicDPDA, automaton::State, automaton::States > { +public: + static bool used ( const automaton::RealTimeHeightDeterministicDPDA & automaton, const automaton::State & state ) { + if ( automaton.getInitialState ( ) == state ) + return true; + + if ( automaton.getFinalStates ( ).count ( state ) ) + return true; + + for (const std::pair<const std::pair<automaton::State, std::variant<::string::Epsilon, alphabet::Symbol>>, std::pair<automaton::State, alphabet::Symbol> >& callTransition : automaton.getCallTransitions()) + if (state == callTransition.first.first || callTransition.second.first == state) + return true; + + for (const std::pair<const std::tuple<automaton::State, std::variant<::string::Epsilon, alphabet::Symbol>, alphabet::Symbol>, automaton::State>& returnTransition : automaton.getReturnTransitions()) + if (state == std::get<0>(returnTransition.first) || returnTransition.second == state) + return true; + + for (const std::pair<const std::pair<automaton::State, std::variant<::string::Epsilon, alphabet::Symbol>>, automaton::State>& localTransition : automaton.getLocalTransitions()) + if (state == localTransition.first.first || localTransition.second == state) + return true; + + return false; + } + + static bool available ( const automaton::RealTimeHeightDeterministicDPDA &, const automaton::State & ) { + return true; + } + + static void valid ( const automaton::RealTimeHeightDeterministicDPDA &, const automaton::State & ) { + } +}; + +template < > +class ComponentConstraint2< automaton::RealTimeHeightDeterministicDPDA, automaton::State, automaton::FinalStates > { +public: + static bool used ( const automaton::RealTimeHeightDeterministicDPDA &, const automaton::State & ) { + return false; + } + + static bool available ( const automaton::RealTimeHeightDeterministicDPDA & automaton, const automaton::State & state ) { + return automaton.accessComponent < automaton::States > ( ).get ( ).count ( state ); + } + + static void valid ( const automaton::RealTimeHeightDeterministicDPDA &, const automaton::State & ) { + } +}; + +template < > +class ElementConstraint2< automaton::RealTimeHeightDeterministicDPDA, automaton::State, automaton::InitialState > { +public: + static bool available ( const automaton::RealTimeHeightDeterministicDPDA & automaton, const automaton::State & state ) { + return automaton.accessComponent < automaton::States > ( ).get ( ).count ( state ); + } + + static void valid ( const automaton::RealTimeHeightDeterministicDPDA &, const automaton::State & ) { + } +}; + +} /* namespace std */ + #endif /* REAL_TIME_HEIGHT_DETERMINISTIC_DPDA_H_ */ diff --git a/alib2data/src/automaton/PDA/RealTimeHeightDeterministicNPDA.cpp b/alib2data/src/automaton/PDA/RealTimeHeightDeterministicNPDA.cpp index be27a9d2a5d04c33eb96cd6f472de3635e205829..7ee296ef4a807a9aad445cb1e3d59cd028f30f42 100644 --- a/alib2data/src/automaton/PDA/RealTimeHeightDeterministicNPDA.cpp +++ b/alib2data/src/automaton/PDA/RealTimeHeightDeterministicNPDA.cpp @@ -6,7 +6,6 @@ */ #include "RealTimeHeightDeterministicNPDA.h" -#include "../AutomatonException.h" #include <algorithm> #include <sstream> @@ -325,153 +324,6 @@ void RealTimeHeightDeterministicNPDA::composeTransitions(std::deque<sax::Token>& } /* namespace automaton */ -namespace std { - -template < > -class ComponentConstraint2< automaton::RealTimeHeightDeterministicNPDA, alphabet::Symbol, automaton::InputAlphabet > { -public: - static bool used ( const automaton::RealTimeHeightDeterministicNPDA & automaton, const alphabet::Symbol & symbol ) { - for (const std::pair<const std::pair<automaton::State, std::variant<::string::Epsilon, alphabet::Symbol>>, std::set<std::pair<automaton::State, alphabet::Symbol> > >& callTransition : automaton.getCallTransitions()) - if (callTransition.first.second.is<alphabet::Symbol>() && symbol == callTransition.first.second.get<alphabet::Symbol>()) - return true; - - for (const std::pair<const std::tuple<automaton::State, std::variant<::string::Epsilon, alphabet::Symbol>, alphabet::Symbol>, std::set<automaton::State> >& returnTransition : automaton.getReturnTransitions()) - if (std::get<1>(returnTransition.first).is<alphabet::Symbol>() && symbol == std::get<1>(returnTransition.first).get<alphabet::Symbol>()) - return true; - - for (const std::pair<const std::pair<automaton::State, std::variant<::string::Epsilon, alphabet::Symbol>>, std::set<automaton::State> >& localTransition : automaton.getLocalTransitions()) - if (localTransition.first.second.is<alphabet::Symbol>() && symbol == localTransition.first.second.get<alphabet::Symbol>()) - return true; - - return false; - } - - static bool available ( const automaton::RealTimeHeightDeterministicNPDA &, const alphabet::Symbol & ) { - return true; - } - - static void valid ( const automaton::RealTimeHeightDeterministicNPDA &, const alphabet::Symbol & ) { - } -}; - -template < > -class ComponentConstraint2< automaton::RealTimeHeightDeterministicNPDA, alphabet::Symbol, automaton::PushdownStoreAlphabet > { -public: - static bool used ( const automaton::RealTimeHeightDeterministicNPDA & automaton, const alphabet::Symbol & symbol ) { - if(automaton.getBottomOfTheStackSymbol() == symbol) - return true; - - for (const std::pair<const std::pair<automaton::State, std::variant<::string::Epsilon, alphabet::Symbol>>, std::set<std::pair<automaton::State, alphabet::Symbol> > >& callTransition : automaton.getCallTransitions()) - for(const std::pair<automaton::State, alphabet::Symbol>& to : callTransition.second) - if (symbol == to.second) - return true; - - for (const std::pair<const std::tuple<automaton::State, std::variant<::string::Epsilon, alphabet::Symbol>, alphabet::Symbol>, std::set<automaton::State> >& returnTransition : automaton.getReturnTransitions()) - if (symbol == std::get<2>(returnTransition.first)) - return true; - - return false; - } - - static bool available ( const automaton::RealTimeHeightDeterministicNPDA &, const alphabet::Symbol & ) { - return true; - } - - static void valid ( const automaton::RealTimeHeightDeterministicNPDA &, const alphabet::Symbol & ) { - } -}; - -template < > -class ElementConstraint2< automaton::RealTimeHeightDeterministicNPDA, alphabet::Symbol, automaton::BottomOfTheStackSymbol > { -public: - static bool available ( const automaton::RealTimeHeightDeterministicNPDA & automaton, const alphabet::Symbol & symbol ) { - return automaton.accessComponent < automaton::PushdownStoreAlphabet > ( ).get ( ).count ( symbol ); - } - - static void valid ( const automaton::RealTimeHeightDeterministicNPDA &, const alphabet::Symbol & ) { - } -}; - -template < > -class ComponentConstraint2< automaton::RealTimeHeightDeterministicNPDA, automaton::State, automaton::States > { -public: - static bool used ( const automaton::RealTimeHeightDeterministicNPDA & automaton, const automaton::State & state ) { - if ( automaton.getInitialStates ( ).count ( state ) ) - return true; - - if ( automaton.getFinalStates ( ).count ( state ) ) - return true; - - for (const std::pair<const std::pair<automaton::State, std::variant<::string::Epsilon, alphabet::Symbol>>, std::set<std::pair<automaton::State, alphabet::Symbol> > >& callTransition : automaton.getCallTransitions()) { - if (state == callTransition.first.first) - return true; - - for(const std::pair<automaton::State, alphabet::Symbol>& target : callTransition.second) - if(target.first == state) - return true; - } - - for (const std::pair<const std::tuple<automaton::State, std::variant<::string::Epsilon, alphabet::Symbol>, alphabet::Symbol>, std::set<automaton::State> >& returnTransition : automaton.getReturnTransitions()) { - if (state == std::get<0>(returnTransition.first)) - return true; - - for(const automaton::State& target : returnTransition.second) - if(target == state) - return true; - } - - for (const std::pair<const std::pair<automaton::State, std::variant<::string::Epsilon, alphabet::Symbol>>, std::set<automaton::State> >& localTransition : automaton.getLocalTransitions()) { - if (state == localTransition.first.first) - return true; - - for(const automaton::State& target : localTransition.second) - if(target == state) - return true; - } - - return false; - } - - static bool available ( const automaton::RealTimeHeightDeterministicNPDA &, const automaton::State & ) { - return true; - } - - static void valid ( const automaton::RealTimeHeightDeterministicNPDA &, const automaton::State & ) { - } -}; - -template < > -class ComponentConstraint2< automaton::RealTimeHeightDeterministicNPDA, automaton::State, automaton::FinalStates > { -public: - static bool used ( const automaton::RealTimeHeightDeterministicNPDA &, const automaton::State & ) { - return false; - } - - static bool available ( const automaton::RealTimeHeightDeterministicNPDA & automaton, const automaton::State & state ) { - return automaton.accessComponent < automaton::States > ( ).get ( ).count ( state ); - } - - static void valid ( const automaton::RealTimeHeightDeterministicNPDA &, const automaton::State & ) { - } -}; - -template < > -class ComponentConstraint2< automaton::RealTimeHeightDeterministicNPDA, automaton::State, automaton::InitialStates > { -public: - static bool used ( const automaton::RealTimeHeightDeterministicNPDA &, const automaton::State & ) { - return false; - } - - static bool available ( const automaton::RealTimeHeightDeterministicNPDA & automaton, const automaton::State & state ) { - return automaton.accessComponent < automaton::States > ( ).get ( ).count ( state ); - } - - static void valid ( const automaton::RealTimeHeightDeterministicNPDA &, const automaton::State & ) { - } -}; - -} /* namespace std */ - namespace alib { auto realTimeHeightDeterministicNPDAParserRegister = xmlApi<automaton::Automaton>::ParserRegister<automaton::RealTimeHeightDeterministicNPDA>(); diff --git a/alib2data/src/automaton/PDA/RealTimeHeightDeterministicNPDA.h b/alib2data/src/automaton/PDA/RealTimeHeightDeterministicNPDA.h index fd10db0a0e6a025086bb5b9410afaf2100f156ef..7944ab776d5e4bf03ba2f9ebf2d36e15ab3a6134 100644 --- a/alib2data/src/automaton/PDA/RealTimeHeightDeterministicNPDA.h +++ b/alib2data/src/automaton/PDA/RealTimeHeightDeterministicNPDA.h @@ -8,6 +8,7 @@ #ifndef REAL_TIME_HEIGHT_DETERMINISTIC_NPDA_H_ #define REAL_TIME_HEIGHT_DETERMINISTIC_NPDA_H_ +#include "../AutomatonException.h" #include <map> #include <vector> #include <variant> @@ -233,4 +234,151 @@ public: } /* namespace automaton */ +namespace std { + +template < > +class ComponentConstraint2< automaton::RealTimeHeightDeterministicNPDA, alphabet::Symbol, automaton::InputAlphabet > { +public: + static bool used ( const automaton::RealTimeHeightDeterministicNPDA & automaton, const alphabet::Symbol & symbol ) { + for (const std::pair<const std::pair<automaton::State, std::variant<::string::Epsilon, alphabet::Symbol>>, std::set<std::pair<automaton::State, alphabet::Symbol> > >& callTransition : automaton.getCallTransitions()) + if (callTransition.first.second.is<alphabet::Symbol>() && symbol == callTransition.first.second.get<alphabet::Symbol>()) + return true; + + for (const std::pair<const std::tuple<automaton::State, std::variant<::string::Epsilon, alphabet::Symbol>, alphabet::Symbol>, std::set<automaton::State> >& returnTransition : automaton.getReturnTransitions()) + if (std::get<1>(returnTransition.first).is<alphabet::Symbol>() && symbol == std::get<1>(returnTransition.first).get<alphabet::Symbol>()) + return true; + + for (const std::pair<const std::pair<automaton::State, std::variant<::string::Epsilon, alphabet::Symbol>>, std::set<automaton::State> >& localTransition : automaton.getLocalTransitions()) + if (localTransition.first.second.is<alphabet::Symbol>() && symbol == localTransition.first.second.get<alphabet::Symbol>()) + return true; + + return false; + } + + static bool available ( const automaton::RealTimeHeightDeterministicNPDA &, const alphabet::Symbol & ) { + return true; + } + + static void valid ( const automaton::RealTimeHeightDeterministicNPDA &, const alphabet::Symbol & ) { + } +}; + +template < > +class ComponentConstraint2< automaton::RealTimeHeightDeterministicNPDA, alphabet::Symbol, automaton::PushdownStoreAlphabet > { +public: + static bool used ( const automaton::RealTimeHeightDeterministicNPDA & automaton, const alphabet::Symbol & symbol ) { + if(automaton.getBottomOfTheStackSymbol() == symbol) + return true; + + for (const std::pair<const std::pair<automaton::State, std::variant<::string::Epsilon, alphabet::Symbol>>, std::set<std::pair<automaton::State, alphabet::Symbol> > >& callTransition : automaton.getCallTransitions()) + for(const std::pair<automaton::State, alphabet::Symbol>& to : callTransition.second) + if (symbol == to.second) + return true; + + for (const std::pair<const std::tuple<automaton::State, std::variant<::string::Epsilon, alphabet::Symbol>, alphabet::Symbol>, std::set<automaton::State> >& returnTransition : automaton.getReturnTransitions()) + if (symbol == std::get<2>(returnTransition.first)) + return true; + + return false; + } + + static bool available ( const automaton::RealTimeHeightDeterministicNPDA &, const alphabet::Symbol & ) { + return true; + } + + static void valid ( const automaton::RealTimeHeightDeterministicNPDA &, const alphabet::Symbol & ) { + } +}; + +template < > +class ElementConstraint2< automaton::RealTimeHeightDeterministicNPDA, alphabet::Symbol, automaton::BottomOfTheStackSymbol > { +public: + static bool available ( const automaton::RealTimeHeightDeterministicNPDA & automaton, const alphabet::Symbol & symbol ) { + return automaton.accessComponent < automaton::PushdownStoreAlphabet > ( ).get ( ).count ( symbol ); + } + + static void valid ( const automaton::RealTimeHeightDeterministicNPDA &, const alphabet::Symbol & ) { + } +}; + +template < > +class ComponentConstraint2< automaton::RealTimeHeightDeterministicNPDA, automaton::State, automaton::States > { +public: + static bool used ( const automaton::RealTimeHeightDeterministicNPDA & automaton, const automaton::State & state ) { + if ( automaton.getInitialStates ( ).count ( state ) ) + return true; + + if ( automaton.getFinalStates ( ).count ( state ) ) + return true; + + for (const std::pair<const std::pair<automaton::State, std::variant<::string::Epsilon, alphabet::Symbol>>, std::set<std::pair<automaton::State, alphabet::Symbol> > >& callTransition : automaton.getCallTransitions()) { + if (state == callTransition.first.first) + return true; + + for(const std::pair<automaton::State, alphabet::Symbol>& target : callTransition.second) + if(target.first == state) + return true; + } + + for (const std::pair<const std::tuple<automaton::State, std::variant<::string::Epsilon, alphabet::Symbol>, alphabet::Symbol>, std::set<automaton::State> >& returnTransition : automaton.getReturnTransitions()) { + if (state == std::get<0>(returnTransition.first)) + return true; + + for(const automaton::State& target : returnTransition.second) + if(target == state) + return true; + } + + for (const std::pair<const std::pair<automaton::State, std::variant<::string::Epsilon, alphabet::Symbol>>, std::set<automaton::State> >& localTransition : automaton.getLocalTransitions()) { + if (state == localTransition.first.first) + return true; + + for(const automaton::State& target : localTransition.second) + if(target == state) + return true; + } + + return false; + } + + static bool available ( const automaton::RealTimeHeightDeterministicNPDA &, const automaton::State & ) { + return true; + } + + static void valid ( const automaton::RealTimeHeightDeterministicNPDA &, const automaton::State & ) { + } +}; + +template < > +class ComponentConstraint2< automaton::RealTimeHeightDeterministicNPDA, automaton::State, automaton::FinalStates > { +public: + static bool used ( const automaton::RealTimeHeightDeterministicNPDA &, const automaton::State & ) { + return false; + } + + static bool available ( const automaton::RealTimeHeightDeterministicNPDA & automaton, const automaton::State & state ) { + return automaton.accessComponent < automaton::States > ( ).get ( ).count ( state ); + } + + static void valid ( const automaton::RealTimeHeightDeterministicNPDA &, const automaton::State & ) { + } +}; + +template < > +class ComponentConstraint2< automaton::RealTimeHeightDeterministicNPDA, automaton::State, automaton::InitialStates > { +public: + static bool used ( const automaton::RealTimeHeightDeterministicNPDA &, const automaton::State & ) { + return false; + } + + static bool available ( const automaton::RealTimeHeightDeterministicNPDA & automaton, const automaton::State & state ) { + return automaton.accessComponent < automaton::States > ( ).get ( ).count ( state ); + } + + static void valid ( const automaton::RealTimeHeightDeterministicNPDA &, const automaton::State & ) { + } +}; + +} /* namespace std */ + #endif /* REAL_TIME_HEIGHT_DETERMINISTIC_NPDA_H_ */ diff --git a/alib2data/src/automaton/PDA/SinglePopDPDA.cpp b/alib2data/src/automaton/PDA/SinglePopDPDA.cpp index 798f22cc1fc9cdfa98878631d1745db9a507b4b7..72a521238d528c0ce52ed3f0b6020df8e5a393b3 100644 --- a/alib2data/src/automaton/PDA/SinglePopDPDA.cpp +++ b/alib2data/src/automaton/PDA/SinglePopDPDA.cpp @@ -6,7 +6,6 @@ */ #include "SinglePopDPDA.h" -#include "../AutomatonException.h" #include <algorithm> #include <sstream> #include <ostream> @@ -225,113 +224,6 @@ void SinglePopDPDA::composeTransitions(std::deque<sax::Token>& out) const { } /* namespace automaton */ -namespace std { - -template < > -class ComponentConstraint2< automaton::SinglePopDPDA, alphabet::Symbol, automaton::InputAlphabet > { -public: - static bool used ( const automaton::SinglePopDPDA & automaton, const alphabet::Symbol & symbol ) { - for (const std::pair<const std::tuple<automaton::State, std::variant<::string::Epsilon, alphabet::Symbol>, alphabet::Symbol>, std::pair<automaton::State, std::vector<alphabet::Symbol> > >& transition : automaton.getTransitions()) - if (std::get<1>(transition.first).is<alphabet::Symbol>() && symbol == std::get<1>(transition.first).get<alphabet::Symbol>()) - return true; - - return false; - } - - static bool available ( const automaton::SinglePopDPDA &, const alphabet::Symbol & ) { - return true; - } - - static void valid ( const automaton::SinglePopDPDA &, const alphabet::Symbol & ) { - } -}; - -template < > -class ComponentConstraint2< automaton::SinglePopDPDA, alphabet::Symbol, automaton::PushdownStoreAlphabet > { -public: - static bool used ( const automaton::SinglePopDPDA & automaton, const alphabet::Symbol & symbol ) { - for (const std::pair<const std::tuple<automaton::State, std::variant<::string::Epsilon, alphabet::Symbol>, alphabet::Symbol>, std::pair<automaton::State, std::vector<alphabet::Symbol> > >& transition : automaton.getTransitions()) - if (symbol == std::get<2>(transition.first) || std::find(transition.second.second.begin(), transition.second.second.end(), symbol) != transition.second.second.end()) - return true; - - if(automaton.getInitialSymbol() == symbol) - return true; - - return false; - } - - static bool available ( const automaton::SinglePopDPDA &, const alphabet::Symbol & ) { - return true; - } - - static void valid ( const automaton::SinglePopDPDA &, const alphabet::Symbol & ) { - } -}; - -template < > -class ElementConstraint2< automaton::SinglePopDPDA, alphabet::Symbol, automaton::InitialSymbol > { -public: - static bool available ( const automaton::SinglePopDPDA & automaton, const alphabet::Symbol & symbol ) { - return automaton.accessComponent < automaton::PushdownStoreAlphabet > ( ).get ( ).count ( symbol ); - } - - static void valid ( const automaton::SinglePopDPDA &, const alphabet::Symbol & ) { - } -}; - -template < > -class ComponentConstraint2< automaton::SinglePopDPDA, automaton::State, automaton::States > { -public: - static bool used ( const automaton::SinglePopDPDA & automaton, const automaton::State & state ) { - if ( automaton.getInitialState ( ) == state ) - return true; - - if ( automaton.getFinalStates ( ).count ( state ) ) - return true; - - for (const std::pair<const std::tuple<automaton::State, std::variant<::string::Epsilon, alphabet::Symbol>, alphabet::Symbol>, std::pair<automaton::State, std::vector<alphabet::Symbol> > >& transition : automaton.getTransitions()) - if (state == std::get<0>(transition.first) || transition.second.first == state) - return true; - - return false; - } - - static bool available ( const automaton::SinglePopDPDA &, const automaton::State & ) { - return true; - } - - static void valid ( const automaton::SinglePopDPDA &, const automaton::State & ) { - } -}; - -template < > -class ComponentConstraint2< automaton::SinglePopDPDA, automaton::State, automaton::FinalStates > { -public: - static bool used ( const automaton::SinglePopDPDA &, const automaton::State & ) { - return false; - } - - static bool available ( const automaton::SinglePopDPDA & automaton, const automaton::State & state ) { - return automaton.accessComponent < automaton::States > ( ).get ( ).count ( state ); - } - - static void valid ( const automaton::SinglePopDPDA &, const automaton::State & ) { - } -}; - -template < > -class ElementConstraint2< automaton::SinglePopDPDA, automaton::State, automaton::InitialState > { -public: - static bool available ( const automaton::SinglePopDPDA & automaton, const automaton::State & state ) { - return automaton.accessComponent < automaton::States > ( ).get ( ).count ( state ); - } - - static void valid ( const automaton::SinglePopDPDA &, const automaton::State & ) { - } -}; - -} /* namespace std */ - namespace alib { auto singlePopDPDAParserRegister = xmlApi<automaton::Automaton>::ParserRegister<automaton::SinglePopDPDA>(); diff --git a/alib2data/src/automaton/PDA/SinglePopDPDA.h b/alib2data/src/automaton/PDA/SinglePopDPDA.h index fedeb6eecc848bfbceeda2b9d5a8b5cccdd94cad..5f696fc48a6cfb1b9639307adea1e82d82f51ad0 100644 --- a/alib2data/src/automaton/PDA/SinglePopDPDA.h +++ b/alib2data/src/automaton/PDA/SinglePopDPDA.h @@ -8,6 +8,7 @@ #ifndef SINGLE_POP_DPDA_H_ #define SINGLE_POP_DPDA_H_ +#include "../AutomatonException.h" #include <set> #include <map> #include <vector> @@ -189,4 +190,111 @@ public: } /* namespace automaton */ +namespace std { + +template < > +class ComponentConstraint2< automaton::SinglePopDPDA, alphabet::Symbol, automaton::InputAlphabet > { +public: + static bool used ( const automaton::SinglePopDPDA & automaton, const alphabet::Symbol & symbol ) { + for (const std::pair<const std::tuple<automaton::State, std::variant<::string::Epsilon, alphabet::Symbol>, alphabet::Symbol>, std::pair<automaton::State, std::vector<alphabet::Symbol> > >& transition : automaton.getTransitions()) + if (std::get<1>(transition.first).is<alphabet::Symbol>() && symbol == std::get<1>(transition.first).get<alphabet::Symbol>()) + return true; + + return false; + } + + static bool available ( const automaton::SinglePopDPDA &, const alphabet::Symbol & ) { + return true; + } + + static void valid ( const automaton::SinglePopDPDA &, const alphabet::Symbol & ) { + } +}; + +template < > +class ComponentConstraint2< automaton::SinglePopDPDA, alphabet::Symbol, automaton::PushdownStoreAlphabet > { +public: + static bool used ( const automaton::SinglePopDPDA & automaton, const alphabet::Symbol & symbol ) { + for (const std::pair<const std::tuple<automaton::State, std::variant<::string::Epsilon, alphabet::Symbol>, alphabet::Symbol>, std::pair<automaton::State, std::vector<alphabet::Symbol> > >& transition : automaton.getTransitions()) + if (symbol == std::get<2>(transition.first) || std::find(transition.second.second.begin(), transition.second.second.end(), symbol) != transition.second.second.end()) + return true; + + if(automaton.getInitialSymbol() == symbol) + return true; + + return false; + } + + static bool available ( const automaton::SinglePopDPDA &, const alphabet::Symbol & ) { + return true; + } + + static void valid ( const automaton::SinglePopDPDA &, const alphabet::Symbol & ) { + } +}; + +template < > +class ElementConstraint2< automaton::SinglePopDPDA, alphabet::Symbol, automaton::InitialSymbol > { +public: + static bool available ( const automaton::SinglePopDPDA & automaton, const alphabet::Symbol & symbol ) { + return automaton.accessComponent < automaton::PushdownStoreAlphabet > ( ).get ( ).count ( symbol ); + } + + static void valid ( const automaton::SinglePopDPDA &, const alphabet::Symbol & ) { + } +}; + +template < > +class ComponentConstraint2< automaton::SinglePopDPDA, automaton::State, automaton::States > { +public: + static bool used ( const automaton::SinglePopDPDA & automaton, const automaton::State & state ) { + if ( automaton.getInitialState ( ) == state ) + return true; + + if ( automaton.getFinalStates ( ).count ( state ) ) + return true; + + for (const std::pair<const std::tuple<automaton::State, std::variant<::string::Epsilon, alphabet::Symbol>, alphabet::Symbol>, std::pair<automaton::State, std::vector<alphabet::Symbol> > >& transition : automaton.getTransitions()) + if (state == std::get<0>(transition.first) || transition.second.first == state) + return true; + + return false; + } + + static bool available ( const automaton::SinglePopDPDA &, const automaton::State & ) { + return true; + } + + static void valid ( const automaton::SinglePopDPDA &, const automaton::State & ) { + } +}; + +template < > +class ComponentConstraint2< automaton::SinglePopDPDA, automaton::State, automaton::FinalStates > { +public: + static bool used ( const automaton::SinglePopDPDA &, const automaton::State & ) { + return false; + } + + static bool available ( const automaton::SinglePopDPDA & automaton, const automaton::State & state ) { + return automaton.accessComponent < automaton::States > ( ).get ( ).count ( state ); + } + + static void valid ( const automaton::SinglePopDPDA &, const automaton::State & ) { + } +}; + +template < > +class ElementConstraint2< automaton::SinglePopDPDA, automaton::State, automaton::InitialState > { +public: + static bool available ( const automaton::SinglePopDPDA & automaton, const automaton::State & state ) { + return automaton.accessComponent < automaton::States > ( ).get ( ).count ( state ); + } + + static void valid ( const automaton::SinglePopDPDA &, const automaton::State & ) { + } +}; + +} /* namespace std */ + #endif /* SINGLE_POP_DPDA_H_ */ diff --git a/alib2data/src/automaton/PDA/SinglePopNPDA.cpp b/alib2data/src/automaton/PDA/SinglePopNPDA.cpp index 8f1ce76ca5bc57a21ac5f2e0299bb8c05035be4a..f2d609bd5af0448bf653d3892ff91288bacef5b7 100644 --- a/alib2data/src/automaton/PDA/SinglePopNPDA.cpp +++ b/alib2data/src/automaton/PDA/SinglePopNPDA.cpp @@ -6,7 +6,6 @@ */ #include "SinglePopNPDA.h" -#include "../AutomatonException.h" #include <algorithm> #include <sstream> @@ -188,123 +187,6 @@ void SinglePopNPDA::composeTransitions(std::deque<sax::Token>& out) const { } /* namespace automaton */ -namespace std { - -template < > -class ComponentConstraint2< automaton::SinglePopNPDA, alphabet::Symbol, automaton::InputAlphabet > { -public: - static bool used ( const automaton::SinglePopNPDA & automaton, const alphabet::Symbol & symbol ) { - for (const std::pair<const std::tuple<automaton::State, std::variant<::string::Epsilon, alphabet::Symbol>, alphabet::Symbol>, std::set<std::pair<automaton::State, std::vector<alphabet::Symbol> > > >& transition : automaton.getTransitions()) - if (std::get<1>(transition.first).is<alphabet::Symbol>() && symbol == std::get<1>(transition.first).get<alphabet::Symbol>()) - return true; - - return false; - } - - static bool available ( const automaton::SinglePopNPDA &, const alphabet::Symbol & ) { - return true; - } - - static void valid ( const automaton::SinglePopNPDA &, const alphabet::Symbol & ) { - } -}; - -template < > -class ComponentConstraint2< automaton::SinglePopNPDA, alphabet::Symbol, automaton::PushdownStoreAlphabet > { -public: - static bool used ( const automaton::SinglePopNPDA & automaton, const alphabet::Symbol & symbol ) { - if(automaton.getInitialSymbol() == symbol) - return true; - - for (const std::pair<const std::tuple<automaton::State, std::variant<::string::Epsilon, alphabet::Symbol>, alphabet::Symbol>, std::set<std::pair<automaton::State, std::vector<alphabet::Symbol> > > >& transition : automaton.getTransitions()) { - if (symbol == std::get<2>(transition.first)) - return true; - - for (const std::pair<automaton::State, std::vector<alphabet::Symbol> >& target : transition.second) - if (std::find(target.second.begin(), target.second.end(), symbol) != target.second.end()) - return true; - } - - return false; - } - - static bool available ( const automaton::SinglePopNPDA &, const alphabet::Symbol & ) { - return true; - } - - static void valid ( const automaton::SinglePopNPDA &, const alphabet::Symbol & ) { - } -}; - -template < > -class ElementConstraint2< automaton::SinglePopNPDA, alphabet::Symbol, automaton::InitialSymbol > { -public: - static bool available ( const automaton::SinglePopNPDA & automaton, const alphabet::Symbol & symbol ) { - return automaton.accessComponent < automaton::PushdownStoreAlphabet > ( ).get ( ).count ( symbol ); - } - - static void valid ( const automaton::SinglePopNPDA &, const alphabet::Symbol & ) { - } -}; - -template < > -class ComponentConstraint2< automaton::SinglePopNPDA, automaton::State, automaton::States > { -public: - static bool used ( const automaton::SinglePopNPDA & automaton, const automaton::State & state ) { - if ( automaton.getInitialState ( ) == state ) - return true; - - if ( automaton.getFinalStates ( ).count ( state ) ) - return true; - - for (const std::pair<const std::tuple<automaton::State, std::variant<::string::Epsilon, alphabet::Symbol>, alphabet::Symbol>, std::set<std::pair<automaton::State, std::vector<alphabet::Symbol> > > >& transition : automaton.getTransitions()) { - if (state == std::get<0>(transition.first)) - return true; - - for(const std::pair<automaton::State, std::vector<alphabet::Symbol> >& target : transition.second) - if(target.first == state) - return true; - } - - return false; - } - - static bool available ( const automaton::SinglePopNPDA &, const automaton::State & ) { - return true; - } - - static void valid ( const automaton::SinglePopNPDA &, const automaton::State & ) { - } -}; - -template < > -class ComponentConstraint2< automaton::SinglePopNPDA, automaton::State, automaton::FinalStates > { -public: - static bool used ( const automaton::SinglePopNPDA &, const automaton::State & ) { - return false; - } - - static bool available ( const automaton::SinglePopNPDA & automaton, const automaton::State & state ) { - return automaton.accessComponent < automaton::States > ( ).get ( ).count ( state ); - } - - static void valid ( const automaton::SinglePopNPDA &, const automaton::State & ) { - } -}; - -template < > -class ElementConstraint2< automaton::SinglePopNPDA, automaton::State, automaton::InitialState > { -public: - static bool available ( const automaton::SinglePopNPDA & automaton, const automaton::State & state ) { - return automaton.accessComponent < automaton::States > ( ).get ( ).count ( state ); - } - - static void valid ( const automaton::SinglePopNPDA &, const automaton::State & ) { - } -}; - -} /* namespace std */ - namespace alib { auto singlePopNPDAParserRegister = xmlApi<automaton::Automaton>::ParserRegister<automaton::SinglePopNPDA>(); diff --git a/alib2data/src/automaton/PDA/SinglePopNPDA.h b/alib2data/src/automaton/PDA/SinglePopNPDA.h index 3434a889c843803f78ccaa7f4107cf05e1bb7636..ae4d2d1b33c1e94624ed244310692b999c7be000 100644 --- a/alib2data/src/automaton/PDA/SinglePopNPDA.h +++ b/alib2data/src/automaton/PDA/SinglePopNPDA.h @@ -8,6 +8,7 @@ #ifndef SINGLE_POP_NPDA_H_ #define SINGLE_POP_NPDA_H_ +#include "../AutomatonException.h" #include <set> #include <map> #include <vector> @@ -185,4 +186,121 @@ public: } /* namespace automaton */ +namespace std { + +template < > +class ComponentConstraint2< automaton::SinglePopNPDA, alphabet::Symbol, automaton::InputAlphabet > { +public: + static bool used ( const automaton::SinglePopNPDA & automaton, const alphabet::Symbol & symbol ) { + for (const std::pair<const std::tuple<automaton::State, std::variant<::string::Epsilon, alphabet::Symbol>, alphabet::Symbol>, std::set<std::pair<automaton::State, std::vector<alphabet::Symbol> > > >& transition : automaton.getTransitions()) + if (std::get<1>(transition.first).is<alphabet::Symbol>() && symbol == std::get<1>(transition.first).get<alphabet::Symbol>()) + return true; + + return false; + } + + static bool available ( const automaton::SinglePopNPDA &, const alphabet::Symbol & ) { + return true; + } + + static void valid ( const automaton::SinglePopNPDA &, const alphabet::Symbol & ) { + } +}; + +template < > +class ComponentConstraint2< automaton::SinglePopNPDA, alphabet::Symbol, automaton::PushdownStoreAlphabet > { +public: + static bool used ( const automaton::SinglePopNPDA & automaton, const alphabet::Symbol & symbol ) { + if(automaton.getInitialSymbol() == symbol) + return true; + + for (const std::pair<const std::tuple<automaton::State, std::variant<::string::Epsilon, alphabet::Symbol>, alphabet::Symbol>, std::set<std::pair<automaton::State, std::vector<alphabet::Symbol> > > >& transition : automaton.getTransitions()) { + if (symbol == std::get<2>(transition.first)) + return true; + + for (const std::pair<automaton::State, std::vector<alphabet::Symbol> >& target : transition.second) + if (std::find(target.second.begin(), target.second.end(), symbol) != target.second.end()) + return true; + } + + return false; + } + + static bool available ( const automaton::SinglePopNPDA &, const alphabet::Symbol & ) { + return true; + } + + static void valid ( const automaton::SinglePopNPDA &, const alphabet::Symbol & ) { + } +}; + +template < > +class ElementConstraint2< automaton::SinglePopNPDA, alphabet::Symbol, automaton::InitialSymbol > { +public: + static bool available ( const automaton::SinglePopNPDA & automaton, const alphabet::Symbol & symbol ) { + return automaton.accessComponent < automaton::PushdownStoreAlphabet > ( ).get ( ).count ( symbol ); + } + + static void valid ( const automaton::SinglePopNPDA &, const alphabet::Symbol & ) { + } +}; + +template < > +class ComponentConstraint2< automaton::SinglePopNPDA, automaton::State, automaton::States > { +public: + static bool used ( const automaton::SinglePopNPDA & automaton, const automaton::State & state ) { + if ( automaton.getInitialState ( ) == state ) + return true; + + if ( automaton.getFinalStates ( ).count ( state ) ) + return true; + + for (const std::pair<const std::tuple<automaton::State, std::variant<::string::Epsilon, alphabet::Symbol>, alphabet::Symbol>, std::set<std::pair<automaton::State, std::vector<alphabet::Symbol> > > >& transition : automaton.getTransitions()) { + if (state == std::get<0>(transition.first)) + return true; + + for(const std::pair<automaton::State, std::vector<alphabet::Symbol> >& target : transition.second) + if(target.first == state) + return true; + } + + return false; + } + + static bool available ( const automaton::SinglePopNPDA &, const automaton::State & ) { + return true; + } + + static void valid ( const automaton::SinglePopNPDA &, const automaton::State & ) { + } +}; + +template < > +class ComponentConstraint2< automaton::SinglePopNPDA, automaton::State, automaton::FinalStates > { +public: + static bool used ( const automaton::SinglePopNPDA &, const automaton::State & ) { + return false; + } + + static bool available ( const automaton::SinglePopNPDA & automaton, const automaton::State & state ) { + return automaton.accessComponent < automaton::States > ( ).get ( ).count ( state ); + } + + static void valid ( const automaton::SinglePopNPDA &, const automaton::State & ) { + } +}; + +template < > +class ElementConstraint2< automaton::SinglePopNPDA, automaton::State, automaton::InitialState > { +public: + static bool available ( const automaton::SinglePopNPDA & automaton, const automaton::State & state ) { + return automaton.accessComponent < automaton::States > ( ).get ( ).count ( state ); + } + + static void valid ( const automaton::SinglePopNPDA &, const automaton::State & ) { + } +}; + +} /* namespace std */ + #endif /* SINGLE_POP_NPDA_H_ */ diff --git a/alib2data/src/automaton/PDA/VisiblyPushdownDPDA.cpp b/alib2data/src/automaton/PDA/VisiblyPushdownDPDA.cpp index 6c01077d60da3c56b777d4522b0f112e2b9f88b7..62bcfbabfee69e833eabaa8e3c45596bac83ef5e 100644 --- a/alib2data/src/automaton/PDA/VisiblyPushdownDPDA.cpp +++ b/alib2data/src/automaton/PDA/VisiblyPushdownDPDA.cpp @@ -6,7 +6,6 @@ */ #include "VisiblyPushdownDPDA.h" -#include "../AutomatonException.h" #include <algorithm> #include <sstream> @@ -340,175 +339,6 @@ void VisiblyPushdownDPDA::composeTransitions(std::deque<sax::Token>& out) const } /* namespace automaton */ -namespace std { - -template < > -class ComponentConstraint2< automaton::VisiblyPushdownDPDA, alphabet::Symbol, automaton::CallAlphabet > { -public: - static bool used ( const automaton::VisiblyPushdownDPDA & automaton, const alphabet::Symbol & symbol ) { - for (const std::pair<const std::pair<automaton::State, alphabet::Symbol>, std::pair<automaton::State, alphabet::Symbol> >& callTransition : automaton.getCallTransitions()) - if (symbol == callTransition.first.second) - return true; - - return false; - } - - static bool available ( const automaton::VisiblyPushdownDPDA &, const alphabet::Symbol & ) { - return true; - } - - static void valid ( const automaton::VisiblyPushdownDPDA & automaton, const alphabet::Symbol & symbol ) { - if(automaton.getLocalInputAlphabet().count(symbol)) - throw automaton::AutomatonException("Input symbol " + (std::string) symbol + " already in local alphabet"); - if(automaton.getReturnInputAlphabet().count(symbol)) - throw automaton::AutomatonException("Input symbol " + (std::string) symbol + " already in return alphabet"); - } -}; - -template < > -class ComponentConstraint2< automaton::VisiblyPushdownDPDA, alphabet::Symbol, automaton::ReturnAlphabet > { -public: - static bool used ( const automaton::VisiblyPushdownDPDA & automaton, const alphabet::Symbol & symbol ) { - for (const std::pair<const std::tuple<automaton::State, alphabet::Symbol, alphabet::Symbol>, automaton::State>& returnTransition : automaton.getReturnTransitions()) - if (symbol == std::get<1>(returnTransition.first)) - return true; - - return false; - } - - static bool available ( const automaton::VisiblyPushdownDPDA &, const alphabet::Symbol & ) { - return true; - } - - static void valid ( const automaton::VisiblyPushdownDPDA & automaton, const alphabet::Symbol & symbol ) { - if(automaton.getLocalInputAlphabet().count(symbol)) - throw automaton::AutomatonException("Input symbol " + (std::string) symbol + " already in local alphabet"); - if(automaton.getCallInputAlphabet().count(symbol)) - throw automaton::AutomatonException("Input symbol " + (std::string) symbol + " already in call alphabet"); - } -}; - -template < > -class ComponentConstraint2< automaton::VisiblyPushdownDPDA, alphabet::Symbol, automaton::LocalAlphabet > { -public: - static bool used ( const automaton::VisiblyPushdownDPDA & automaton, const alphabet::Symbol & symbol ) { - for (const std::pair<const std::pair<automaton::State, alphabet::Symbol>, automaton::State>& localTransition : automaton.getLocalTransitions()) - if (symbol == localTransition.first.second) - return true; - - return false; - } - - static bool available ( const automaton::VisiblyPushdownDPDA &, const alphabet::Symbol & ) { - return true; - } - - static void valid ( const automaton::VisiblyPushdownDPDA & automaton, const alphabet::Symbol & symbol ) { - if(automaton.getReturnInputAlphabet().count(symbol)) - throw automaton::AutomatonException("Input symbol " + (std::string) symbol + " already in return alphabet"); - if(automaton.getCallInputAlphabet().count(symbol)) - throw automaton::AutomatonException("Input symbol " + (std::string) symbol + " already in call alphabet"); - } -}; - -template < > -class ComponentConstraint2< automaton::VisiblyPushdownDPDA, alphabet::Symbol, automaton::PushdownStoreAlphabet > { -public: - static bool used ( const automaton::VisiblyPushdownDPDA & automaton, const alphabet::Symbol & symbol ) { - for (const std::pair<const std::pair<automaton::State, alphabet::Symbol>, std::pair<automaton::State, alphabet::Symbol> >& callTransition : automaton.getCallTransitions()) - if (symbol == callTransition.second.second) - return true; - - for (const std::pair<const std::tuple<automaton::State, alphabet::Symbol, alphabet::Symbol>, automaton::State>& returnTransition : automaton.getReturnTransitions()) - if (symbol == std::get<2>(returnTransition.first)) - return true; - - if(automaton.getBottomOfTheStackSymbol() == symbol) - return true; - - return false; - } - - static bool available ( const automaton::VisiblyPushdownDPDA &, const alphabet::Symbol & ) { - return true; - } - - static void valid ( const automaton::VisiblyPushdownDPDA &, const alphabet::Symbol & ) { - } -}; - -template < > -class ElementConstraint2< automaton::VisiblyPushdownDPDA, alphabet::Symbol, automaton::BottomOfTheStackSymbol > { -public: - static bool available ( const automaton::VisiblyPushdownDPDA & automaton, const alphabet::Symbol & symbol ) { - return automaton.accessComponent < automaton::PushdownStoreAlphabet > ( ).get ( ).count ( symbol ); - } - - static void valid ( const automaton::VisiblyPushdownDPDA &, const alphabet::Symbol & ) { - } -}; - -template < > -class ComponentConstraint2< automaton::VisiblyPushdownDPDA, automaton::State, automaton::States > { -public: - static bool used ( const automaton::VisiblyPushdownDPDA & automaton, const automaton::State & state ) { - if ( automaton.getInitialState ( ) == state ) - return true; - - if ( automaton.getFinalStates ( ).count ( state ) ) - return true; - - for (const std::pair<const std::pair<automaton::State, alphabet::Symbol>, std::pair<automaton::State, alphabet::Symbol> >& callTransition : automaton.getCallTransitions()) - if (state == callTransition.first.first || callTransition.second.first == state) - return true; - - for (const std::pair<const std::tuple<automaton::State, alphabet::Symbol, alphabet::Symbol>, automaton::State>& returnTransition : automaton.getReturnTransitions()) - if (state == std::get<0>(returnTransition.first) || returnTransition.second == state) - return true; - - for (const std::pair<const std::pair<automaton::State, alphabet::Symbol>, automaton::State>& localTransition : automaton.getLocalTransitions()) - if (state == localTransition.first.first || localTransition.second == state) - return true; - - return false; - } - - static bool available ( const automaton::VisiblyPushdownDPDA &, const automaton::State & ) { - return true; - } - - static void valid ( const automaton::VisiblyPushdownDPDA &, const automaton::State & ) { - } -}; - -template < > -class ComponentConstraint2< automaton::VisiblyPushdownDPDA, automaton::State, automaton::FinalStates > { -public: - static bool used ( const automaton::VisiblyPushdownDPDA &, const automaton::State & ) { - return false; - } - - static bool available ( const automaton::VisiblyPushdownDPDA & automaton, const automaton::State & state ) { - return automaton.accessComponent < automaton::States > ( ).get ( ).count ( state ); - } - - static void valid ( const automaton::VisiblyPushdownDPDA &, const automaton::State & ) { - } -}; - -template < > -class ElementConstraint2< automaton::VisiblyPushdownDPDA, automaton::State, automaton::InitialState > { -public: - static bool available ( const automaton::VisiblyPushdownDPDA & automaton, const automaton::State & state ) { - return automaton.accessComponent < automaton::States > ( ).get ( ).count ( state ); - } - - static void valid ( const automaton::VisiblyPushdownDPDA &, const automaton::State & ) { - } -}; - -} /* namespace std */ - namespace alib { auto visiblyPushdownDPDAParserRegister = xmlApi<automaton::Automaton>::ParserRegister<automaton::VisiblyPushdownDPDA>(); diff --git a/alib2data/src/automaton/PDA/VisiblyPushdownDPDA.h b/alib2data/src/automaton/PDA/VisiblyPushdownDPDA.h index 847f4c996ff1c96e01b923cb3668b10185123235..69a44031381352aa5ba897655e248c651f035e05 100644 --- a/alib2data/src/automaton/PDA/VisiblyPushdownDPDA.h +++ b/alib2data/src/automaton/PDA/VisiblyPushdownDPDA.h @@ -8,6 +8,7 @@ #ifndef VISIBLY_PUSHDOWN_DPDA_H_ #define VISIBLY_PUSHDOWN_DPDA_H_ +#include "../AutomatonException.h" #include <map> #include <vector> #include <core/components2.hpp> @@ -257,4 +258,173 @@ public: } /* namespace automaton */ +namespace std { + +template < > +class ComponentConstraint2< automaton::VisiblyPushdownDPDA, alphabet::Symbol, automaton::CallAlphabet > { +public: + static bool used ( const automaton::VisiblyPushdownDPDA & automaton, const alphabet::Symbol & symbol ) { + for (const std::pair<const std::pair<automaton::State, alphabet::Symbol>, std::pair<automaton::State, alphabet::Symbol> >& callTransition : automaton.getCallTransitions()) + if (symbol == callTransition.first.second) + return true; + + return false; + } + + static bool available ( const automaton::VisiblyPushdownDPDA &, const alphabet::Symbol & ) { + return true; + } + + static void valid ( const automaton::VisiblyPushdownDPDA & automaton, const alphabet::Symbol & symbol ) { + if(automaton.getLocalInputAlphabet().count(symbol)) + throw automaton::AutomatonException("Input symbol " + (std::string) symbol + " already in local alphabet"); + if(automaton.getReturnInputAlphabet().count(symbol)) + throw automaton::AutomatonException("Input symbol " + (std::string) symbol + " already in return alphabet"); + } +}; + +template < > +class ComponentConstraint2< automaton::VisiblyPushdownDPDA, alphabet::Symbol, automaton::ReturnAlphabet > { +public: + static bool used ( const automaton::VisiblyPushdownDPDA & automaton, const alphabet::Symbol & symbol ) { + for (const std::pair<const std::tuple<automaton::State, alphabet::Symbol, alphabet::Symbol>, automaton::State>& returnTransition : automaton.getReturnTransitions()) + if (symbol == std::get<1>(returnTransition.first)) + return true; + + return false; + } + + static bool available ( const automaton::VisiblyPushdownDPDA &, const alphabet::Symbol & ) { + return true; + } + + static void valid ( const automaton::VisiblyPushdownDPDA & automaton, const alphabet::Symbol & symbol ) { + if(automaton.getLocalInputAlphabet().count(symbol)) + throw automaton::AutomatonException("Input symbol " + (std::string) symbol + " already in local alphabet"); + if(automaton.getCallInputAlphabet().count(symbol)) + throw automaton::AutomatonException("Input symbol " + (std::string) symbol + " already in call alphabet"); + } +}; + +template < > +class ComponentConstraint2< automaton::VisiblyPushdownDPDA, alphabet::Symbol, automaton::LocalAlphabet > { +public: + static bool used ( const automaton::VisiblyPushdownDPDA & automaton, const alphabet::Symbol & symbol ) { + for (const std::pair<const std::pair<automaton::State, alphabet::Symbol>, automaton::State>& localTransition : automaton.getLocalTransitions()) + if (symbol == localTransition.first.second) + return true; + + return false; + } + + static bool available ( const automaton::VisiblyPushdownDPDA &, const alphabet::Symbol & ) { + return true; + } + + static void valid ( const automaton::VisiblyPushdownDPDA & automaton, const alphabet::Symbol & symbol ) { + if(automaton.getReturnInputAlphabet().count(symbol)) + throw automaton::AutomatonException("Input symbol " + (std::string) symbol + " already in return alphabet"); + if(automaton.getCallInputAlphabet().count(symbol)) + throw automaton::AutomatonException("Input symbol " + (std::string) symbol + " already in call alphabet"); + } +}; + +template < > +class ComponentConstraint2< automaton::VisiblyPushdownDPDA, alphabet::Symbol, automaton::PushdownStoreAlphabet > { +public: + static bool used ( const automaton::VisiblyPushdownDPDA & automaton, const alphabet::Symbol & symbol ) { + for (const std::pair<const std::pair<automaton::State, alphabet::Symbol>, std::pair<automaton::State, alphabet::Symbol> >& callTransition : automaton.getCallTransitions()) + if (symbol == callTransition.second.second) + return true; + + for (const std::pair<const std::tuple<automaton::State, alphabet::Symbol, alphabet::Symbol>, automaton::State>& returnTransition : automaton.getReturnTransitions()) + if (symbol == std::get<2>(returnTransition.first)) + return true; + + if(automaton.getBottomOfTheStackSymbol() == symbol) + return true; + + return false; + } + + static bool available ( const automaton::VisiblyPushdownDPDA &, const alphabet::Symbol & ) { + return true; + } + + static void valid ( const automaton::VisiblyPushdownDPDA &, const alphabet::Symbol & ) { + } +}; + +template < > +class ElementConstraint2< automaton::VisiblyPushdownDPDA, alphabet::Symbol, automaton::BottomOfTheStackSymbol > { +public: + static bool available ( const automaton::VisiblyPushdownDPDA & automaton, const alphabet::Symbol & symbol ) { + return automaton.accessComponent < automaton::PushdownStoreAlphabet > ( ).get ( ).count ( symbol ); + } + + static void valid ( const automaton::VisiblyPushdownDPDA &, const alphabet::Symbol & ) { + } +}; + +template < > +class ComponentConstraint2< automaton::VisiblyPushdownDPDA, automaton::State, automaton::States > { +public: + static bool used ( const automaton::VisiblyPushdownDPDA & automaton, const automaton::State & state ) { + if ( automaton.getInitialState ( ) == state ) + return true; + + if ( automaton.getFinalStates ( ).count ( state ) ) + return true; + + for (const std::pair<const std::pair<automaton::State, alphabet::Symbol>, std::pair<automaton::State, alphabet::Symbol> >& callTransition : automaton.getCallTransitions()) + if (state == callTransition.first.first || callTransition.second.first == state) + return true; + + for (const std::pair<const std::tuple<automaton::State, alphabet::Symbol, alphabet::Symbol>, automaton::State>& returnTransition : automaton.getReturnTransitions()) + if (state == std::get<0>(returnTransition.first) || returnTransition.second == state) + return true; + + for (const std::pair<const std::pair<automaton::State, alphabet::Symbol>, automaton::State>& localTransition : automaton.getLocalTransitions()) + if (state == localTransition.first.first || localTransition.second == state) + return true; + + return false; + } + + static bool available ( const automaton::VisiblyPushdownDPDA &, const automaton::State & ) { + return true; + } + + static void valid ( const automaton::VisiblyPushdownDPDA &, const automaton::State & ) { + } +}; + +template < > +class ComponentConstraint2< automaton::VisiblyPushdownDPDA, automaton::State, automaton::FinalStates > { +public: + static bool used ( const automaton::VisiblyPushdownDPDA &, const automaton::State & ) { + return false; + } + + static bool available ( const automaton::VisiblyPushdownDPDA & automaton, const automaton::State & state ) { + return automaton.accessComponent < automaton::States > ( ).get ( ).count ( state ); + } + + static void valid ( const automaton::VisiblyPushdownDPDA &, const automaton::State & ) { + } +}; + +template < > +class ElementConstraint2< automaton::VisiblyPushdownDPDA, automaton::State, automaton::InitialState > { +public: + static bool available ( const automaton::VisiblyPushdownDPDA & automaton, const automaton::State & state ) { + return automaton.accessComponent < automaton::States > ( ).get ( ).count ( state ); + } + + static void valid ( const automaton::VisiblyPushdownDPDA &, const automaton::State & ) { + } +}; + +} /* namespace std */ + #endif /* VISIBLY_PUSHDOWN_DPDA_H_ */ diff --git a/alib2data/src/automaton/PDA/VisiblyPushdownNPDA.cpp b/alib2data/src/automaton/PDA/VisiblyPushdownNPDA.cpp index 847b661860c19b5805496dc2b7e7f4be4b4af731..8eaed1f632c7ffae104be47f56efb41da06e216c 100644 --- a/alib2data/src/automaton/PDA/VisiblyPushdownNPDA.cpp +++ b/alib2data/src/automaton/PDA/VisiblyPushdownNPDA.cpp @@ -6,7 +6,6 @@ */ #include "VisiblyPushdownNPDA.h" -#include "../AutomatonException.h" #include <algorithm> #include <sstream> @@ -272,195 +271,6 @@ void VisiblyPushdownNPDA::composeTransitions(std::deque<sax::Token>& out) const } /* namespace automaton */ -namespace std { - -template < > -class ComponentConstraint2< automaton::VisiblyPushdownNPDA, alphabet::Symbol, automaton::CallAlphabet > { -public: - static bool used ( const automaton::VisiblyPushdownNPDA & automaton, const alphabet::Symbol & symbol ) { - for (const std::pair<const std::pair<automaton::State, alphabet::Symbol>, std::set < std::pair<automaton::State, alphabet::Symbol> > >& callTransition : automaton.getCallTransitions()) - if (symbol == callTransition.first.second) - return true; - - return false; - } - - static bool available ( const automaton::VisiblyPushdownNPDA &, const alphabet::Symbol & ) { - return true; - } - - static void valid ( const automaton::VisiblyPushdownNPDA & automaton, const alphabet::Symbol & symbol ) { - if(automaton.getLocalInputAlphabet().count(symbol)) - throw automaton::AutomatonException("Input symbol " + (std::string) symbol + " already in local alphabet"); - if(automaton.getReturnInputAlphabet().count(symbol)) - throw automaton::AutomatonException("Input symbol " + (std::string) symbol + " already in return alphabet"); - } -}; - -template < > -class ComponentConstraint2< automaton::VisiblyPushdownNPDA, alphabet::Symbol, automaton::ReturnAlphabet > { -public: - static bool used ( const automaton::VisiblyPushdownNPDA & automaton, const alphabet::Symbol & symbol ) { - for (const std::pair<const std::tuple<automaton::State, alphabet::Symbol, alphabet::Symbol>, std::set < automaton::State> >& returnTransition : automaton.getReturnTransitions()) - if (symbol == std::get<1>(returnTransition.first)) - return true; - - return false; - } - - static bool available ( const automaton::VisiblyPushdownNPDA &, const alphabet::Symbol & ) { - return true; - } - - static void valid ( const automaton::VisiblyPushdownNPDA & automaton, const alphabet::Symbol & symbol ) { - if(automaton.getLocalInputAlphabet().count(symbol)) - throw automaton::AutomatonException("Input symbol " + (std::string) symbol + " already in local alphabet"); - if(automaton.getCallInputAlphabet().count(symbol)) - throw automaton::AutomatonException("Input symbol " + (std::string) symbol + " already in call alphabet"); - } -}; - -template < > -class ComponentConstraint2< automaton::VisiblyPushdownNPDA, alphabet::Symbol, automaton::LocalAlphabet > { -public: - static bool used ( const automaton::VisiblyPushdownNPDA & automaton, const alphabet::Symbol & symbol ) { - for (const std::pair<const std::pair<automaton::State, alphabet::Symbol>, std::set < automaton::State >>& localTransition : automaton.getLocalTransitions()) - if (symbol == localTransition.first.second) - return true; - - return false; - } - - static bool available ( const automaton::VisiblyPushdownNPDA &, const alphabet::Symbol & ) { - return true; - } - - static void valid ( const automaton::VisiblyPushdownNPDA & automaton, const alphabet::Symbol & symbol ) { - if(automaton.getReturnInputAlphabet().count(symbol)) - throw automaton::AutomatonException("Input symbol " + (std::string) symbol + " already in return alphabet"); - if(automaton.getCallInputAlphabet().count(symbol)) - throw automaton::AutomatonException("Input symbol " + (std::string) symbol + " already in call alphabet"); - } -}; - -template < > -class ComponentConstraint2< automaton::VisiblyPushdownNPDA, alphabet::Symbol, automaton::PushdownStoreAlphabet > { -public: - static bool used ( const automaton::VisiblyPushdownNPDA & automaton, const alphabet::Symbol & symbol ) { - for (const std::pair<const std::pair<automaton::State, alphabet::Symbol>, std::set<std::pair<automaton::State, alphabet::Symbol> > >& callTransition : automaton.getCallTransitions()) - for(const std::pair<automaton::State, alphabet::Symbol>& to : callTransition.second) - if (symbol == to.second) - return true; - - for (const std::pair<const std::tuple<automaton::State, alphabet::Symbol, alphabet::Symbol>, std::set<automaton::State> >& returnTransition : automaton.getReturnTransitions()) - if (symbol == std::get<2>(returnTransition.first)) - return true; - - if(automaton.getBottomOfTheStackSymbol() == symbol) - return true; - - return false; - } - - static bool available ( const automaton::VisiblyPushdownNPDA &, const alphabet::Symbol & ) { - return true; - } - - static void valid ( const automaton::VisiblyPushdownNPDA &, const alphabet::Symbol & ) { - } -}; - -template < > -class ElementConstraint2< automaton::VisiblyPushdownNPDA, alphabet::Symbol, automaton::BottomOfTheStackSymbol > { -public: - static bool available ( const automaton::VisiblyPushdownNPDA & automaton, const alphabet::Symbol & symbol ) { - return automaton.accessComponent < automaton::PushdownStoreAlphabet > ( ).get ( ).count ( symbol ); - } - - static void valid ( const automaton::VisiblyPushdownNPDA &, const alphabet::Symbol & ) { - } -}; - -template < > -class ComponentConstraint2< automaton::VisiblyPushdownNPDA, automaton::State, automaton::States > { -public: - static bool used ( const automaton::VisiblyPushdownNPDA & automaton, const automaton::State & state ) { - if ( automaton.getInitialStates ( ).count ( state ) ) - return true; - - if ( automaton.getFinalStates ( ).count ( state ) ) - return true; - - for (const std::pair<const std::pair<automaton::State, alphabet::Symbol>, std::set<std::pair<automaton::State, alphabet::Symbol> > >& callTransition : automaton.getCallTransitions()) { - if (state == callTransition.first.first) - return true; - for(const std::pair<automaton::State, alphabet::Symbol>& target : callTransition.second) { - if(target.first == state) - return true; - } - } - - for (const std::pair<const std::tuple<automaton::State, alphabet::Symbol, alphabet::Symbol>, std::set<automaton::State> >& returnTransition : automaton.getReturnTransitions()) { - if (state == std::get<0>(returnTransition.first)) - return true; - for(const automaton::State& target : returnTransition.second) { - if(target == state) - return true; - } - } - - for (const std::pair<const std::pair<automaton::State, alphabet::Symbol>, std::set<automaton::State> >& localTransition : automaton.getLocalTransitions()) { - if (state == localTransition.first.first) - return true; - for(const automaton::State& target : localTransition.second) { - if(target == state) - return true; - } - } - - return false; - } - - static bool available ( const automaton::VisiblyPushdownNPDA &, const automaton::State & ) { - return true; - } - - static void valid ( const automaton::VisiblyPushdownNPDA &, const automaton::State & ) { - } -}; - -template < > -class ComponentConstraint2< automaton::VisiblyPushdownNPDA, automaton::State, automaton::FinalStates > { -public: - static bool used ( const automaton::VisiblyPushdownNPDA &, const automaton::State & ) { - return false; - } - - static bool available ( const automaton::VisiblyPushdownNPDA & automaton, const automaton::State & state ) { - return automaton.accessComponent < automaton::States > ( ).get ( ).count ( state ); - } - - static void valid ( const automaton::VisiblyPushdownNPDA &, const automaton::State & ) { - } -}; - -template < > -class ComponentConstraint2< automaton::VisiblyPushdownNPDA, automaton::State, automaton::InitialStates > { -public: - static bool used ( const automaton::VisiblyPushdownNPDA &, const automaton::State & ) { - return false; - } - - static bool available ( const automaton::VisiblyPushdownNPDA & automaton, const automaton::State & state ) { - return automaton.accessComponent < automaton::States > ( ).get ( ).count ( state ); - } - - static void valid ( const automaton::VisiblyPushdownNPDA &, const automaton::State & ) { - } -}; - -} /* namespace std */ - namespace alib { auto visiblyPushdownNPDAParserRegister = xmlApi<automaton::Automaton>::ParserRegister<automaton::VisiblyPushdownNPDA>(); diff --git a/alib2data/src/automaton/PDA/VisiblyPushdownNPDA.h b/alib2data/src/automaton/PDA/VisiblyPushdownNPDA.h index 1ba58d8b780683b079742853133440dca4665302..85e4a77122d7ce1fa6b11bd521442dfa337de3ac 100644 --- a/alib2data/src/automaton/PDA/VisiblyPushdownNPDA.h +++ b/alib2data/src/automaton/PDA/VisiblyPushdownNPDA.h @@ -8,6 +8,7 @@ #ifndef VISIBLY_PUSHDOWN_NPDA_H_ #define VISIBLY_PUSHDOWN_NPDA_H_ +#include "../AutomatonException.h" #include <map> #include <vector> #include <core/components2.hpp> @@ -265,4 +266,193 @@ public: } /* namespace automaton */ +namespace std { + +template < > +class ComponentConstraint2< automaton::VisiblyPushdownNPDA, alphabet::Symbol, automaton::CallAlphabet > { +public: + static bool used ( const automaton::VisiblyPushdownNPDA & automaton, const alphabet::Symbol & symbol ) { + for (const std::pair<const std::pair<automaton::State, alphabet::Symbol>, std::set < std::pair<automaton::State, alphabet::Symbol> > >& callTransition : automaton.getCallTransitions()) + if (symbol == callTransition.first.second) + return true; + + return false; + } + + static bool available ( const automaton::VisiblyPushdownNPDA &, const alphabet::Symbol & ) { + return true; + } + + static void valid ( const automaton::VisiblyPushdownNPDA & automaton, const alphabet::Symbol & symbol ) { + if(automaton.getLocalInputAlphabet().count(symbol)) + throw automaton::AutomatonException("Input symbol " + (std::string) symbol + " already in local alphabet"); + if(automaton.getReturnInputAlphabet().count(symbol)) + throw automaton::AutomatonException("Input symbol " + (std::string) symbol + " already in return alphabet"); + } +}; + +template < > +class ComponentConstraint2< automaton::VisiblyPushdownNPDA, alphabet::Symbol, automaton::ReturnAlphabet > { +public: + static bool used ( const automaton::VisiblyPushdownNPDA & automaton, const alphabet::Symbol & symbol ) { + for (const std::pair<const std::tuple<automaton::State, alphabet::Symbol, alphabet::Symbol>, std::set < automaton::State> >& returnTransition : automaton.getReturnTransitions()) + if (symbol == std::get<1>(returnTransition.first)) + return true; + + return false; + } + + static bool available ( const automaton::VisiblyPushdownNPDA &, const alphabet::Symbol & ) { + return true; + } + + static void valid ( const automaton::VisiblyPushdownNPDA & automaton, const alphabet::Symbol & symbol ) { + if(automaton.getLocalInputAlphabet().count(symbol)) + throw automaton::AutomatonException("Input symbol " + (std::string) symbol + " already in local alphabet"); + if(automaton.getCallInputAlphabet().count(symbol)) + throw automaton::AutomatonException("Input symbol " + (std::string) symbol + " already in call alphabet"); + } +}; + +template < > +class ComponentConstraint2< automaton::VisiblyPushdownNPDA, alphabet::Symbol, automaton::LocalAlphabet > { +public: + static bool used ( const automaton::VisiblyPushdownNPDA & automaton, const alphabet::Symbol & symbol ) { + for (const std::pair<const std::pair<automaton::State, alphabet::Symbol>, std::set < automaton::State >>& localTransition : automaton.getLocalTransitions()) + if (symbol == localTransition.first.second) + return true; + + return false; + } + + static bool available ( const automaton::VisiblyPushdownNPDA &, const alphabet::Symbol & ) { + return true; + } + + static void valid ( const automaton::VisiblyPushdownNPDA & automaton, const alphabet::Symbol & symbol ) { + if(automaton.getReturnInputAlphabet().count(symbol)) + throw automaton::AutomatonException("Input symbol " + (std::string) symbol + " already in return alphabet"); + if(automaton.getCallInputAlphabet().count(symbol)) + throw automaton::AutomatonException("Input symbol " + (std::string) symbol + " already in call alphabet"); + } +}; + +template < > +class ComponentConstraint2< automaton::VisiblyPushdownNPDA, alphabet::Symbol, automaton::PushdownStoreAlphabet > { +public: + static bool used ( const automaton::VisiblyPushdownNPDA & automaton, const alphabet::Symbol & symbol ) { + for (const std::pair<const std::pair<automaton::State, alphabet::Symbol>, std::set<std::pair<automaton::State, alphabet::Symbol> > >& callTransition : automaton.getCallTransitions()) + for(const std::pair<automaton::State, alphabet::Symbol>& to : callTransition.second) + if (symbol == to.second) + return true; + + for (const std::pair<const std::tuple<automaton::State, alphabet::Symbol, alphabet::Symbol>, std::set<automaton::State> >& returnTransition : automaton.getReturnTransitions()) + if (symbol == std::get<2>(returnTransition.first)) + return true; + + if(automaton.getBottomOfTheStackSymbol() == symbol) + return true; + + return false; + } + + static bool available ( const automaton::VisiblyPushdownNPDA &, const alphabet::Symbol & ) { + return true; + } + + static void valid ( const automaton::VisiblyPushdownNPDA &, const alphabet::Symbol & ) { + } +}; + +template < > +class ElementConstraint2< automaton::VisiblyPushdownNPDA, alphabet::Symbol, automaton::BottomOfTheStackSymbol > { +public: + static bool available ( const automaton::VisiblyPushdownNPDA & automaton, const alphabet::Symbol & symbol ) { + return automaton.accessComponent < automaton::PushdownStoreAlphabet > ( ).get ( ).count ( symbol ); + } + + static void valid ( const automaton::VisiblyPushdownNPDA &, const alphabet::Symbol & ) { + } +}; + +template < > +class ComponentConstraint2< automaton::VisiblyPushdownNPDA, automaton::State, automaton::States > { +public: + static bool used ( const automaton::VisiblyPushdownNPDA & automaton, const automaton::State & state ) { + if ( automaton.getInitialStates ( ).count ( state ) ) + return true; + + if ( automaton.getFinalStates ( ).count ( state ) ) + return true; + + for (const std::pair<const std::pair<automaton::State, alphabet::Symbol>, std::set<std::pair<automaton::State, alphabet::Symbol> > >& callTransition : automaton.getCallTransitions()) { + if (state == callTransition.first.first) + return true; + for(const std::pair<automaton::State, alphabet::Symbol>& target : callTransition.second) { + if(target.first == state) + return true; + } + } + + for (const std::pair<const std::tuple<automaton::State, alphabet::Symbol, alphabet::Symbol>, std::set<automaton::State> >& returnTransition : automaton.getReturnTransitions()) { + if (state == std::get<0>(returnTransition.first)) + return true; + for(const automaton::State& target : returnTransition.second) { + if(target == state) + return true; + } + } + + for (const std::pair<const std::pair<automaton::State, alphabet::Symbol>, std::set<automaton::State> >& localTransition : automaton.getLocalTransitions()) { + if (state == localTransition.first.first) + return true; + for(const automaton::State& target : localTransition.second) { + if(target == state) + return true; + } + } + + return false; + } + + static bool available ( const automaton::VisiblyPushdownNPDA &, const automaton::State & ) { + return true; + } + + static void valid ( const automaton::VisiblyPushdownNPDA &, const automaton::State & ) { + } +}; + +template < > +class ComponentConstraint2< automaton::VisiblyPushdownNPDA, automaton::State, automaton::FinalStates > { +public: + static bool used ( const automaton::VisiblyPushdownNPDA &, const automaton::State & ) { + return false; + } + + static bool available ( const automaton::VisiblyPushdownNPDA & automaton, const automaton::State & state ) { + return automaton.accessComponent < automaton::States > ( ).get ( ).count ( state ); + } + + static void valid ( const automaton::VisiblyPushdownNPDA &, const automaton::State & ) { + } +}; + +template < > +class ComponentConstraint2< automaton::VisiblyPushdownNPDA, automaton::State, automaton::InitialStates > { +public: + static bool used ( const automaton::VisiblyPushdownNPDA &, const automaton::State & ) { + return false; + } + + static bool available ( const automaton::VisiblyPushdownNPDA & automaton, const automaton::State & state ) { + return automaton.accessComponent < automaton::States > ( ).get ( ).count ( state ); + } + + static void valid ( const automaton::VisiblyPushdownNPDA &, const automaton::State & ) { + } +}; + +} /* namespace std */ + #endif /* VISIBLY_PUSHDOWN_NPDA_H_ */ diff --git a/alib2data/src/automaton/TA/DFTA.cpp b/alib2data/src/automaton/TA/DFTA.cpp index c0eb0a32f328d4c0262683a87ae9358fb222442d..f5d166e84e3ff9297c36a36879c3bf493e8ceff3 100644 --- a/alib2data/src/automaton/TA/DFTA.cpp +++ b/alib2data/src/automaton/TA/DFTA.cpp @@ -6,7 +6,6 @@ */ #include "DFTA.h" -#include "../AutomatonException.h" #include <ostream> #include <sstream> @@ -152,66 +151,6 @@ void DFTA::composeTransitions(std::deque<sax::Token>& out) const { } /* namespace automaton */ -namespace std { - -template < > -class ComponentConstraint2< automaton::DFTA, alphabet::RankedSymbol, automaton::InputAlphabet > { -public: - static bool used ( const automaton::DFTA & automaton, const alphabet::RankedSymbol & symbol ) { - for (const std::pair<const std::pair<alphabet::RankedSymbol, std::vector<automaton::State> >, automaton::State>& t : automaton.getTransitions()) - if (t.first.first == symbol) - return true; - - return false; - } - - static bool available ( const automaton::DFTA &, const alphabet::RankedSymbol & ) { - return true; - } - - static void valid ( const automaton::DFTA &, const alphabet::RankedSymbol & ) { - } -}; - -template < > -class ComponentConstraint2< automaton::DFTA, automaton::State, automaton::States > { -public: - static bool used ( const automaton::DFTA & automaton, const automaton::State & state ) { - if ( automaton.getFinalStates ( ).count ( state ) ) - return true; - - for (const std::pair<const std::pair<alphabet::RankedSymbol, std::vector<automaton::State> >, automaton::State>& t : automaton.getTransitions()) - if(std::contains(t.first.second.begin(), t.first.second.end(), state ) || t.second == state) - return true; - - return false; - } - - static bool available ( const automaton::DFTA &, const automaton::State & ) { - return true; - } - - static void valid ( const automaton::DFTA &, const automaton::State & ) { - } -}; - -template < > -class ComponentConstraint2< automaton::DFTA, automaton::State, automaton::FinalStates > { -public: - static bool used ( const automaton::DFTA &, const automaton::State & ) { - return false; - } - - static bool available ( const automaton::DFTA & automaton, const automaton::State & state ) { - return automaton.accessComponent < automaton::States > ( ).get ( ).count ( state ); - } - - static void valid ( const automaton::DFTA &, const automaton::State & ) { - } -}; - -} /* namespace std */ - namespace alib { auto DFTAParserRegister = xmlApi<automaton::Automaton>::ParserRegister<automaton::DFTA>(); diff --git a/alib2data/src/automaton/TA/DFTA.h b/alib2data/src/automaton/TA/DFTA.h index 93d2cfd12386ba79043a227d18a0253f14ba4dcf..73b8c1c02bf7d8280ff49fe27e4bd4da1b88e44d 100644 --- a/alib2data/src/automaton/TA/DFTA.h +++ b/alib2data/src/automaton/TA/DFTA.h @@ -8,6 +8,7 @@ #ifndef DFTA_H_ #define DFTA_H_ +#include "../AutomatonException.h" #include <map> #include <vector> #include <core/components2.hpp> @@ -139,4 +140,64 @@ public: } /* namespace automaton */ +namespace std { + +template < > +class ComponentConstraint2< automaton::DFTA, alphabet::RankedSymbol, automaton::InputAlphabet > { +public: + static bool used ( const automaton::DFTA & automaton, const alphabet::RankedSymbol & symbol ) { + for (const std::pair<const std::pair<alphabet::RankedSymbol, std::vector<automaton::State> >, automaton::State>& t : automaton.getTransitions()) + if (t.first.first == symbol) + return true; + + return false; + } + + static bool available ( const automaton::DFTA &, const alphabet::RankedSymbol & ) { + return true; + } + + static void valid ( const automaton::DFTA &, const alphabet::RankedSymbol & ) { + } +}; + +template < > +class ComponentConstraint2< automaton::DFTA, automaton::State, automaton::States > { +public: + static bool used ( const automaton::DFTA & automaton, const automaton::State & state ) { + if ( automaton.getFinalStates ( ).count ( state ) ) + return true; + + for (const std::pair<const std::pair<alphabet::RankedSymbol, std::vector<automaton::State> >, automaton::State>& t : automaton.getTransitions()) + if(std::contains(t.first.second.begin(), t.first.second.end(), state ) || t.second == state) + return true; + + return false; + } + + static bool available ( const automaton::DFTA &, const automaton::State & ) { + return true; + } + + static void valid ( const automaton::DFTA &, const automaton::State & ) { + } +}; + +template < > +class ComponentConstraint2< automaton::DFTA, automaton::State, automaton::FinalStates > { +public: + static bool used ( const automaton::DFTA &, const automaton::State & ) { + return false; + } + + static bool available ( const automaton::DFTA & automaton, const automaton::State & state ) { + return automaton.accessComponent < automaton::States > ( ).get ( ).count ( state ); + } + + static void valid ( const automaton::DFTA &, const automaton::State & ) { + } +}; + +} /* namespace std */ + #endif /* DFTA_H_ */ diff --git a/alib2data/src/automaton/TA/NFTA.cpp b/alib2data/src/automaton/TA/NFTA.cpp index e90e5958f077085f88559badd169cb442d472b8e..d5271d46be7b5cbc96fce48340df4a6a371cb38b 100644 --- a/alib2data/src/automaton/TA/NFTA.cpp +++ b/alib2data/src/automaton/TA/NFTA.cpp @@ -6,7 +6,6 @@ */ #include "NFTA.h" -#include "../AutomatonException.h" #include <ostream> #include <sstream> @@ -161,66 +160,6 @@ void NFTA::composeTransitions(std::deque<sax::Token>& out) const { } /* namespace automaton */ -namespace std { - -template < > -class ComponentConstraint2< automaton::NFTA, alphabet::RankedSymbol, automaton::InputAlphabet > { -public: - static bool used ( const automaton::NFTA & automaton, const alphabet::RankedSymbol & symbol ) { - for (const std::pair<const std::pair<alphabet::RankedSymbol, std::vector<automaton::State> >, std::set<automaton::State>>& t : automaton.getTransitions()) - if (t.first.first == symbol) - return true; - - return false; - } - - static bool available ( const automaton::NFTA &, const alphabet::RankedSymbol & ) { - return true; - } - - static void valid ( const automaton::NFTA &, const alphabet::RankedSymbol & ) { - } -}; - -template < > -class ComponentConstraint2< automaton::NFTA, automaton::State, automaton::States > { -public: - static bool used ( const automaton::NFTA & automaton, const automaton::State & state ) { - if ( automaton.getFinalStates ( ).count ( state ) ) - return true; - - for (const std::pair<const std::pair<alphabet::RankedSymbol, std::vector<automaton::State> >, std::set<automaton::State>>& t : automaton.getTransitions()) - if(std::contains(t.first.second.begin(), t.first.second.end(), state ) || t . second.count ( state ) ) - return true; - - return false; - } - - static bool available ( const automaton::NFTA &, const automaton::State & ) { - return true; - } - - static void valid ( const automaton::NFTA &, const automaton::State & ) { - } -}; - -template < > -class ComponentConstraint2< automaton::NFTA, automaton::State, automaton::FinalStates > { -public: - static bool used ( const automaton::NFTA &, const automaton::State & ) { - return false; - } - - static bool available ( const automaton::NFTA & automaton, const automaton::State & state ) { - return automaton.accessComponent < automaton::States > ( ).get ( ).count ( state ); - } - - static void valid ( const automaton::NFTA &, const automaton::State & ) { - } -}; - -} /* namespace std */ - namespace alib { auto NFTAParserRegister = xmlApi<automaton::Automaton>::ParserRegister<automaton::NFTA>(); diff --git a/alib2data/src/automaton/TA/NFTA.h b/alib2data/src/automaton/TA/NFTA.h index 3e74762962769c01a25890ac1c6a227e6bb9a46d..4ac94c13f0c4df080054dfda3eff33b54bff497a 100644 --- a/alib2data/src/automaton/TA/NFTA.h +++ b/alib2data/src/automaton/TA/NFTA.h @@ -8,6 +8,7 @@ #ifndef NFTA_H_ #define NFTA_H_ +#include "../AutomatonException.h" #include <map> #include <vector> #include <core/components2.hpp> @@ -151,4 +152,64 @@ public: } /* namespace automaton */ +namespace std { + +template < > +class ComponentConstraint2< automaton::NFTA, alphabet::RankedSymbol, automaton::InputAlphabet > { +public: + static bool used ( const automaton::NFTA & automaton, const alphabet::RankedSymbol & symbol ) { + for (const std::pair<const std::pair<alphabet::RankedSymbol, std::vector<automaton::State> >, std::set<automaton::State>>& t : automaton.getTransitions()) + if (t.first.first == symbol) + return true; + + return false; + } + + static bool available ( const automaton::NFTA &, const alphabet::RankedSymbol & ) { + return true; + } + + static void valid ( const automaton::NFTA &, const alphabet::RankedSymbol & ) { + } +}; + +template < > +class ComponentConstraint2< automaton::NFTA, automaton::State, automaton::States > { +public: + static bool used ( const automaton::NFTA & automaton, const automaton::State & state ) { + if ( automaton.getFinalStates ( ).count ( state ) ) + return true; + + for (const std::pair<const std::pair<alphabet::RankedSymbol, std::vector<automaton::State> >, std::set<automaton::State>>& t : automaton.getTransitions()) + if(std::contains(t.first.second.begin(), t.first.second.end(), state ) || t . second.count ( state ) ) + return true; + + return false; + } + + static bool available ( const automaton::NFTA &, const automaton::State & ) { + return true; + } + + static void valid ( const automaton::NFTA &, const automaton::State & ) { + } +}; + +template < > +class ComponentConstraint2< automaton::NFTA, automaton::State, automaton::FinalStates > { +public: + static bool used ( const automaton::NFTA &, const automaton::State & ) { + return false; + } + + static bool available ( const automaton::NFTA & automaton, const automaton::State & state ) { + return automaton.accessComponent < automaton::States > ( ).get ( ).count ( state ); + } + + static void valid ( const automaton::NFTA &, const automaton::State & ) { + } +}; + +} /* namespace std */ + #endif /* NFTA_H_ */ diff --git a/alib2data/src/automaton/TM/OneTapeDTM.cpp b/alib2data/src/automaton/TM/OneTapeDTM.cpp index 88c4caf5e5caf7a706fb45ffbc9a6126f35fbe55..3b4cc1728bdcbbc431c958a930e22ef39023696f 100644 --- a/alib2data/src/automaton/TM/OneTapeDTM.cpp +++ b/alib2data/src/automaton/TM/OneTapeDTM.cpp @@ -6,7 +6,6 @@ */ #include "OneTapeDTM.h" -#include "../AutomatonException.h" #include <sstream> #include <sax/FromXMLParserHelper.h> @@ -177,117 +176,6 @@ void OneTapeDTM::composeTransitions(std::deque<sax::Token>& out) const { } /* namespace automaton */ -namespace std { - -template < > -class ComponentConstraint2< automaton::OneTapeDTM, alphabet::Symbol, automaton::TapeAlphabet > { -public: - static bool used ( const automaton::OneTapeDTM & automaton, const alphabet::Symbol & symbol ) { - if ( automaton.getBlankSymbol ( ) == symbol ) - return true; - - if ( automaton.getInputAlphabet().count(symbol)) - return true; - - for (const std::pair<const std::pair<automaton::State, alphabet::Symbol>, std::tuple<automaton::State, alphabet::Symbol, automaton::Shift> >& transition : automaton.getTransitions()) - if (symbol == transition.first.second || symbol == std::get<1>(transition.second)) - return true; - - return false; - - } - - static bool available ( const automaton::OneTapeDTM &, const alphabet::Symbol & ) { - return true; - } - - static void valid ( const automaton::OneTapeDTM &, const alphabet::Symbol & ) { - } -}; - -template < > -class ComponentConstraint2< automaton::OneTapeDTM, alphabet::Symbol, automaton::InputAlphabet > { -public: - static bool used ( const automaton::OneTapeDTM &, const alphabet::Symbol & ) { - return false; - } - - static bool available ( const automaton::OneTapeDTM & automaton, const alphabet::Symbol & symbol ) { - return automaton.accessComponent < automaton::TapeAlphabet > ( ).get ( ).count ( symbol ); - } - - static void valid ( const automaton::OneTapeDTM & automaton, const alphabet::Symbol & symbol ) { - if (symbol == automaton.getBlankSymbol()) - throw automaton::AutomatonException("Input symbol \"" + (std::string) symbol + "\" cannot be blank symbol."); - } -}; - -template < > -class ElementConstraint2< automaton::OneTapeDTM, alphabet::Symbol, automaton::BlankSymbol > { -public: - static bool available ( const automaton::OneTapeDTM & automaton, const alphabet::Symbol & symbol ) { - return automaton.accessComponent < automaton::TapeAlphabet > ( ).get ( ).count ( symbol ); - } - - static void valid ( const automaton::OneTapeDTM & automaton, const alphabet::Symbol & symbol ) { - if (automaton.getInputAlphabet().count( symbol )) - throw automaton::AutomatonException("Blank symbol \"" + (std::string) symbol + "\" cannot be in input alphabet."); - } -}; - -template < > -class ComponentConstraint2< automaton::OneTapeDTM, automaton::State, automaton::States > { -public: - static bool used ( const automaton::OneTapeDTM & automaton, const automaton::State & state ) { - if ( automaton.getInitialState ( ) == state ) - return true; - - if ( automaton.getFinalStates ( ).count ( state ) ) - return true; - - for (const std::pair<const std::pair<automaton::State, alphabet::Symbol>, std::tuple<automaton::State, alphabet::Symbol, automaton::Shift> >& transition : automaton.getTransitions ( ) ) - if ( state == transition.first.first || state == std::get < 0 > ( transition.second ) ) - return true; - - return false; - } - - static bool available ( const automaton::OneTapeDTM &, const automaton::State & ) { - return true; - } - - static void valid ( const automaton::OneTapeDTM &, const automaton::State & ) { - } -}; - -template < > -class ComponentConstraint2< automaton::OneTapeDTM, automaton::State, automaton::FinalStates > { -public: - static bool used ( const automaton::OneTapeDTM &, const automaton::State & ) { - return false; - } - - static bool available ( const automaton::OneTapeDTM & automaton, const automaton::State & state ) { - return automaton.accessComponent < automaton::States > ( ).get ( ).count ( state ); - } - - static void valid ( const automaton::OneTapeDTM &, const automaton::State & ) { - } -}; - -template < > -class ElementConstraint2< automaton::OneTapeDTM, automaton::State, automaton::InitialState > { -public: - static bool available ( const automaton::OneTapeDTM & automaton, const automaton::State & state ) { - return automaton.accessComponent < automaton::States > ( ).get ( ).count ( state ); - } - - static void valid ( const automaton::OneTapeDTM &, const automaton::State & ) { - } -}; - -} /* namespace std */ - namespace alib { auto oneTapeDTMParserRegister = xmlApi<automaton::Automaton>::ParserRegister<automaton::OneTapeDTM>(); diff --git a/alib2data/src/automaton/TM/OneTapeDTM.h b/alib2data/src/automaton/TM/OneTapeDTM.h index fca58dab5d7de3431405ca96519562b87088b22c..c41aac391dc6f8d396d5ca4049d1e598ea3fd8cc 100644 --- a/alib2data/src/automaton/TM/OneTapeDTM.h +++ b/alib2data/src/automaton/TM/OneTapeDTM.h @@ -8,6 +8,7 @@ #ifndef ONE_TAPE_DTM_H_ #define ONE_TAPE_DTM_H_ +#include "../AutomatonException.h" #include "../AutomatonBase.h" #include <core/components2.hpp> #include "../common/State.h" @@ -178,4 +179,115 @@ public: } /* namespace automaton */ +namespace std { + +template < > +class ComponentConstraint2< automaton::OneTapeDTM, alphabet::Symbol, automaton::TapeAlphabet > { +public: + static bool used ( const automaton::OneTapeDTM & automaton, const alphabet::Symbol & symbol ) { + if ( automaton.getBlankSymbol ( ) == symbol ) + return true; + + if ( automaton.getInputAlphabet().count(symbol)) + return true; + + for (const std::pair<const std::pair<automaton::State, alphabet::Symbol>, std::tuple<automaton::State, alphabet::Symbol, automaton::Shift> >& transition : automaton.getTransitions()) + if (symbol == transition.first.second || symbol == std::get<1>(transition.second)) + return true; + + return false; + + } + + static bool available ( const automaton::OneTapeDTM &, const alphabet::Symbol & ) { + return true; + } + + static void valid ( const automaton::OneTapeDTM &, const alphabet::Symbol & ) { + } +}; + +template < > +class ComponentConstraint2< automaton::OneTapeDTM, alphabet::Symbol, automaton::InputAlphabet > { +public: + static bool used ( const automaton::OneTapeDTM &, const alphabet::Symbol & ) { + return false; + } + + static bool available ( const automaton::OneTapeDTM & automaton, const alphabet::Symbol & symbol ) { + return automaton.accessComponent < automaton::TapeAlphabet > ( ).get ( ).count ( symbol ); + } + + static void valid ( const automaton::OneTapeDTM & automaton, const alphabet::Symbol & symbol ) { + if (symbol == automaton.getBlankSymbol()) + throw automaton::AutomatonException("Input symbol \"" + (std::string) symbol + "\" cannot be blank symbol."); + } +}; + +template < > +class ElementConstraint2< automaton::OneTapeDTM, alphabet::Symbol, automaton::BlankSymbol > { +public: + static bool available ( const automaton::OneTapeDTM & automaton, const alphabet::Symbol & symbol ) { + return automaton.accessComponent < automaton::TapeAlphabet > ( ).get ( ).count ( symbol ); + } + + static void valid ( const automaton::OneTapeDTM & automaton, const alphabet::Symbol & symbol ) { + if (automaton.getInputAlphabet().count( symbol )) + throw automaton::AutomatonException("Blank symbol \"" + (std::string) symbol + "\" cannot be in input alphabet."); + } +}; + +template < > +class ComponentConstraint2< automaton::OneTapeDTM, automaton::State, automaton::States > { +public: + static bool used ( const automaton::OneTapeDTM & automaton, const automaton::State & state ) { + if ( automaton.getInitialState ( ) == state ) + return true; + + if ( automaton.getFinalStates ( ).count ( state ) ) + return true; + + for (const std::pair<const std::pair<automaton::State, alphabet::Symbol>, std::tuple<automaton::State, alphabet::Symbol, automaton::Shift> >& transition : automaton.getTransitions ( ) ) + if ( state == transition.first.first || state == std::get < 0 > ( transition.second ) ) + return true; + + return false; + } + + static bool available ( const automaton::OneTapeDTM &, const automaton::State & ) { + return true; + } + + static void valid ( const automaton::OneTapeDTM &, const automaton::State & ) { + } +}; + +template < > +class ComponentConstraint2< automaton::OneTapeDTM, automaton::State, automaton::FinalStates > { +public: + static bool used ( const automaton::OneTapeDTM &, const automaton::State & ) { + return false; + } + + static bool available ( const automaton::OneTapeDTM & automaton, const automaton::State & state ) { + return automaton.accessComponent < automaton::States > ( ).get ( ).count ( state ); + } + + static void valid ( const automaton::OneTapeDTM &, const automaton::State & ) { + } +}; + +template < > +class ElementConstraint2< automaton::OneTapeDTM, automaton::State, automaton::InitialState > { +public: + static bool available ( const automaton::OneTapeDTM & automaton, const automaton::State & state ) { + return automaton.accessComponent < automaton::States > ( ).get ( ).count ( state ); + } + + static void valid ( const automaton::OneTapeDTM &, const automaton::State & ) { + } +}; + +} /* namespace std */ + #endif /* ONE_TAPE_DTM_H_ */ diff --git a/alib2data/src/grammar/ContextFree/CFG.cpp b/alib2data/src/grammar/ContextFree/CFG.cpp index 181d32d2edf8b81ac42d8ce6e438bc88c6c2f849..6d3aa43d0029a5dfe95bb99c02fdb9b3abab465f 100644 --- a/alib2data/src/grammar/ContextFree/CFG.cpp +++ b/alib2data/src/grammar/ContextFree/CFG.cpp @@ -6,7 +6,6 @@ */ #include "CFG.h" -#include "../GrammarException.h" #include <algorithm> #include <sstream> @@ -154,73 +153,6 @@ void CFG::composeRules ( std::deque < sax::Token > & out ) const { } /* namespace grammar */ -namespace std { - -template < > -class ComponentConstraint2< grammar::CFG, alphabet::Symbol, grammar::TerminalAlphabet > { -public: - static bool used ( const grammar::CFG & grammar, const alphabet::Symbol & symbol ) { - for ( const std::pair < const alphabet::Symbol, std::set < std::vector < alphabet::Symbol > > > & rule : grammar.getRules ( ) ) - for ( const std::vector < alphabet::Symbol > & rhs : rule.second ) - if ( std::find ( rhs.begin ( ), rhs.end ( ), symbol ) != rhs.end ( ) ) - return true; - - return false; - } - - static bool available ( const grammar::CFG &, const alphabet::Symbol & ) { - return true; - } - - static void valid ( const grammar::CFG & grammar, const alphabet::Symbol & symbol ) { - if ( grammar.accessComponent < grammar::NonterminalAlphabet > ( ).get ( ).count ( symbol ) ) - throw grammar::GrammarException ( "Symbol " + ( std::string ) symbol + "cannot be in terminal alphabet since it is already nonterminal alphabet" ); - } -}; - -template < > -class ComponentConstraint2< grammar::CFG, alphabet::Symbol, grammar::NonterminalAlphabet > { -public: - static bool used ( const grammar::CFG & grammar, const alphabet::Symbol & symbol ) { - for ( const std::pair < const alphabet::Symbol, std::set < std::vector < alphabet::Symbol > > > & rule : grammar.getRules ( ) ) { - if ( rule.first == symbol ) - return true; - - for ( const std::vector < alphabet::Symbol > & rhs : rule.second ) - if ( std::find ( rhs.begin ( ), rhs.end ( ), symbol ) != rhs.end ( ) ) - return true; - - } - - if ( grammar.accessElement < grammar::InitialSymbol > ( ).get ( ) == symbol ) - return true; - - return false; - } - - static bool available ( const grammar::CFG &, const alphabet::Symbol & ) { - return true; - } - - static void valid ( const grammar::CFG & grammar, const alphabet::Symbol & symbol ) { - if ( grammar.accessComponent < grammar::TerminalAlphabet > ( ).get ( ).count ( symbol ) ) - throw grammar::GrammarException ( "Symbol " + ( std::string ) symbol + "cannot be in nonterminal alphabet since it is already in terminal alphabet" ); - } -}; - -template < > -class ElementConstraint2< grammar::CFG, alphabet::Symbol, grammar::InitialSymbol > { -public: - static bool available ( const grammar::CFG & grammar, const alphabet::Symbol & symbol ) { - return grammar.accessComponent < grammar::NonterminalAlphabet > ( ).get ( ).count ( symbol ); - } - - static void valid ( const grammar::CFG &, const alphabet::Symbol & ) { - } -}; - -} /* namespace std */ - namespace alib { auto CFGParserRegister = xmlApi < grammar::Grammar >::ParserRegister < grammar::CFG > ( ); diff --git a/alib2data/src/grammar/ContextFree/CFG.h b/alib2data/src/grammar/ContextFree/CFG.h index 5496edf78b611b1508b92c1a965990e532d84e0c..4b934db22c2275fa57a897be5df5d40ef25e4e5c 100644 --- a/alib2data/src/grammar/ContextFree/CFG.h +++ b/alib2data/src/grammar/ContextFree/CFG.h @@ -8,6 +8,7 @@ #ifndef CFG_H_ #define CFG_H_ +#include "../GrammarException.h" #include "../GrammarBase.h" #include "EpsilonFreeCFG.h" #include <map> @@ -109,4 +110,71 @@ public: } /* namespace grammar */ +namespace std { + +template < > +class ComponentConstraint2< grammar::CFG, alphabet::Symbol, grammar::TerminalAlphabet > { +public: + static bool used ( const grammar::CFG & grammar, const alphabet::Symbol & symbol ) { + for ( const std::pair < const alphabet::Symbol, std::set < std::vector < alphabet::Symbol > > > & rule : grammar.getRules ( ) ) + for ( const std::vector < alphabet::Symbol > & rhs : rule.second ) + if ( std::find ( rhs.begin ( ), rhs.end ( ), symbol ) != rhs.end ( ) ) + return true; + + return false; + } + + static bool available ( const grammar::CFG &, const alphabet::Symbol & ) { + return true; + } + + static void valid ( const grammar::CFG & grammar, const alphabet::Symbol & symbol ) { + if ( grammar.accessComponent < grammar::NonterminalAlphabet > ( ).get ( ).count ( symbol ) ) + throw grammar::GrammarException ( "Symbol " + ( std::string ) symbol + "cannot be in terminal alphabet since it is already nonterminal alphabet" ); + } +}; + +template < > +class ComponentConstraint2< grammar::CFG, alphabet::Symbol, grammar::NonterminalAlphabet > { +public: + static bool used ( const grammar::CFG & grammar, const alphabet::Symbol & symbol ) { + for ( const std::pair < const alphabet::Symbol, std::set < std::vector < alphabet::Symbol > > > & rule : grammar.getRules ( ) ) { + if ( rule.first == symbol ) + return true; + + for ( const std::vector < alphabet::Symbol > & rhs : rule.second ) + if ( std::find ( rhs.begin ( ), rhs.end ( ), symbol ) != rhs.end ( ) ) + return true; + + } + + if ( grammar.accessElement < grammar::InitialSymbol > ( ).get ( ) == symbol ) + return true; + + return false; + } + + static bool available ( const grammar::CFG &, const alphabet::Symbol & ) { + return true; + } + + static void valid ( const grammar::CFG & grammar, const alphabet::Symbol & symbol ) { + if ( grammar.accessComponent < grammar::TerminalAlphabet > ( ).get ( ).count ( symbol ) ) + throw grammar::GrammarException ( "Symbol " + ( std::string ) symbol + "cannot be in nonterminal alphabet since it is already in terminal alphabet" ); + } +}; + +template < > +class ElementConstraint2< grammar::CFG, alphabet::Symbol, grammar::InitialSymbol > { +public: + static bool available ( const grammar::CFG & grammar, const alphabet::Symbol & symbol ) { + return grammar.accessComponent < grammar::NonterminalAlphabet > ( ).get ( ).count ( symbol ); + } + + static void valid ( const grammar::CFG &, const alphabet::Symbol & ) { + } +}; + +} /* namespace std */ + #endif /* CFG_H_ */ diff --git a/alib2data/src/grammar/ContextFree/CNF.cpp b/alib2data/src/grammar/ContextFree/CNF.cpp index fd6010f50e545ec7404f512fdff1f5b71be5cb4d..94dc9a4adc42a1e235a5393acfce2eba92f37590 100644 --- a/alib2data/src/grammar/ContextFree/CNF.cpp +++ b/alib2data/src/grammar/ContextFree/CNF.cpp @@ -6,7 +6,6 @@ */ #include "CNF.h" -#include "../GrammarException.h" #include <algorithm> #include <sstream> @@ -236,73 +235,6 @@ void CNF::composeRules ( std::deque < sax::Token > & out ) const { } /* namespace grammar */ -namespace std { - -template < > -class ComponentConstraint2< grammar::CNF, alphabet::Symbol, grammar::TerminalAlphabet > { -public: - static bool used ( const grammar::CNF & grammar, const alphabet::Symbol & symbol ) { - for ( const std::pair < const alphabet::Symbol, std::set < std::variant < alphabet::Symbol, std::pair < alphabet::Symbol, alphabet::Symbol > > > > & rule : grammar.getRules ( ) ) - for ( const std::variant < alphabet::Symbol, std::pair < alphabet::Symbol, alphabet::Symbol > > & rhs : rule.second ) - if ( ( rhs.is < alphabet::Symbol > ( ) && ( rhs.get < alphabet::Symbol > ( ) == symbol ) ) || ( rhs.get < std::pair < alphabet::Symbol, alphabet::Symbol > > ( ).first == symbol ) ) - return true; - - return false; - } - - static bool available ( const grammar::CNF &, const alphabet::Symbol & ) { - return true; - } - - static void valid ( const grammar::CNF & grammar, const alphabet::Symbol & symbol ) { - if ( grammar.accessComponent < grammar::NonterminalAlphabet > ( ).get ( ).count ( symbol ) ) - throw grammar::GrammarException ( "Symbol " + ( std::string ) symbol + "cannot be in terminal alphabet since it is already nonterminal alphabet" ); - } -}; - -template < > -class ComponentConstraint2< grammar::CNF, alphabet::Symbol, grammar::NonterminalAlphabet > { -public: - static bool used ( const grammar::CNF & grammar, const alphabet::Symbol & symbol ) { - for ( const std::pair < const alphabet::Symbol, std::set < std::variant < alphabet::Symbol, std::pair < alphabet::Symbol, alphabet::Symbol > > > > & rule : grammar.getRules ( ) ) { - if ( rule.first == symbol ) - return true; - - for ( const std::variant < alphabet::Symbol, std::pair < alphabet::Symbol, alphabet::Symbol > > & rhs : rule.second ) - if ( rhs.get < std::pair < alphabet::Symbol, alphabet::Symbol > > ( ).second == symbol ) - return true; - - } - - if ( grammar.accessElement < grammar::InitialSymbol > ( ).get ( ) == symbol ) - return true; - - return false; - } - - static bool available ( const grammar::CNF &, const alphabet::Symbol & ) { - return true; - } - - static void valid ( const grammar::CNF & grammar, const alphabet::Symbol & symbol ) { - if ( grammar.accessComponent < grammar::TerminalAlphabet > ( ).get ( ).count ( symbol ) ) - throw grammar::GrammarException ( "Symbol " + ( std::string ) symbol + "cannot be in nonterminal alphabet since it is already in terminal alphabet" ); - } -}; - -template < > -class ElementConstraint2< grammar::CNF, alphabet::Symbol, grammar::InitialSymbol > { -public: - static bool available ( const grammar::CNF & grammar, const alphabet::Symbol & symbol ) { - return grammar.accessComponent < grammar::NonterminalAlphabet > ( ).get ( ).count ( symbol ); - } - - static void valid ( const grammar::CNF &, const alphabet::Symbol & ) { - } -}; - -} /* namespace std */ - namespace alib { auto CNFParserRegister = xmlApi < grammar::Grammar >::ParserRegister < grammar::CNF > ( ); diff --git a/alib2data/src/grammar/ContextFree/CNF.h b/alib2data/src/grammar/ContextFree/CNF.h index a835e9d20588c4698574029e4bd01e785a80aa2d..b9c20afb8cd5d52f1228a210c5665ef1a7be0613 100644 --- a/alib2data/src/grammar/ContextFree/CNF.h +++ b/alib2data/src/grammar/ContextFree/CNF.h @@ -8,6 +8,7 @@ #ifndef CNF_H_ #define CNF_H_ +#include "../GrammarException.h" #include "../GrammarBase.h" #include <map> #include <vector> @@ -115,4 +116,71 @@ public: } /* namespace grammar */ +namespace std { + +template < > +class ComponentConstraint2< grammar::CNF, alphabet::Symbol, grammar::TerminalAlphabet > { +public: + static bool used ( const grammar::CNF & grammar, const alphabet::Symbol & symbol ) { + for ( const std::pair < const alphabet::Symbol, std::set < std::variant < alphabet::Symbol, std::pair < alphabet::Symbol, alphabet::Symbol > > > > & rule : grammar.getRules ( ) ) + for ( const std::variant < alphabet::Symbol, std::pair < alphabet::Symbol, alphabet::Symbol > > & rhs : rule.second ) + if ( ( rhs.is < alphabet::Symbol > ( ) && ( rhs.get < alphabet::Symbol > ( ) == symbol ) ) || ( rhs.get < std::pair < alphabet::Symbol, alphabet::Symbol > > ( ).first == symbol ) ) + return true; + + return false; + } + + static bool available ( const grammar::CNF &, const alphabet::Symbol & ) { + return true; + } + + static void valid ( const grammar::CNF & grammar, const alphabet::Symbol & symbol ) { + if ( grammar.accessComponent < grammar::NonterminalAlphabet > ( ).get ( ).count ( symbol ) ) + throw grammar::GrammarException ( "Symbol " + ( std::string ) symbol + "cannot be in terminal alphabet since it is already nonterminal alphabet" ); + } +}; + +template < > +class ComponentConstraint2< grammar::CNF, alphabet::Symbol, grammar::NonterminalAlphabet > { +public: + static bool used ( const grammar::CNF & grammar, const alphabet::Symbol & symbol ) { + for ( const std::pair < const alphabet::Symbol, std::set < std::variant < alphabet::Symbol, std::pair < alphabet::Symbol, alphabet::Symbol > > > > & rule : grammar.getRules ( ) ) { + if ( rule.first == symbol ) + return true; + + for ( const std::variant < alphabet::Symbol, std::pair < alphabet::Symbol, alphabet::Symbol > > & rhs : rule.second ) + if ( rhs.get < std::pair < alphabet::Symbol, alphabet::Symbol > > ( ).second == symbol ) + return true; + + } + + if ( grammar.accessElement < grammar::InitialSymbol > ( ).get ( ) == symbol ) + return true; + + return false; + } + + static bool available ( const grammar::CNF &, const alphabet::Symbol & ) { + return true; + } + + static void valid ( const grammar::CNF & grammar, const alphabet::Symbol & symbol ) { + if ( grammar.accessComponent < grammar::TerminalAlphabet > ( ).get ( ).count ( symbol ) ) + throw grammar::GrammarException ( "Symbol " + ( std::string ) symbol + "cannot be in nonterminal alphabet since it is already in terminal alphabet" ); + } +}; + +template < > +class ElementConstraint2< grammar::CNF, alphabet::Symbol, grammar::InitialSymbol > { +public: + static bool available ( const grammar::CNF & grammar, const alphabet::Symbol & symbol ) { + return grammar.accessComponent < grammar::NonterminalAlphabet > ( ).get ( ).count ( symbol ); + } + + static void valid ( const grammar::CNF &, const alphabet::Symbol & ) { + } +}; + +} /* namespace std */ + #endif /* CNF_H_ */ diff --git a/alib2data/src/grammar/ContextFree/EpsilonFreeCFG.cpp b/alib2data/src/grammar/ContextFree/EpsilonFreeCFG.cpp index 1a88fbf0a0ac6a1b3ef5f1e7aa7e1bb11d22dba9..50d9a7abb7c1ccbc6b847a2068999ca6d967eb91 100644 --- a/alib2data/src/grammar/ContextFree/EpsilonFreeCFG.cpp +++ b/alib2data/src/grammar/ContextFree/EpsilonFreeCFG.cpp @@ -6,7 +6,6 @@ */ #include "EpsilonFreeCFG.h" -#include "../GrammarException.h" #include <algorithm> #include <sstream> @@ -183,73 +182,6 @@ void EpsilonFreeCFG::composeRules ( std::deque < sax::Token > & out ) const { } /* namespace grammar */ -namespace std { - -template < > -class ComponentConstraint2< grammar::EpsilonFreeCFG, alphabet::Symbol, grammar::TerminalAlphabet > { -public: - static bool used ( const grammar::EpsilonFreeCFG & grammar, const alphabet::Symbol & symbol ) { - for ( const std::pair < const alphabet::Symbol, std::set < std::vector < alphabet::Symbol > > > & rule : grammar.getRules ( ) ) - for ( const std::vector < alphabet::Symbol > & rhs : rule.second ) - if ( std::find ( rhs.begin ( ), rhs.end ( ), symbol ) != rhs.end ( ) ) - return true; - - return false; - } - - static bool available ( const grammar::EpsilonFreeCFG &, const alphabet::Symbol & ) { - return true; - } - - static void valid ( const grammar::EpsilonFreeCFG & grammar, const alphabet::Symbol & symbol ) { - if ( grammar.accessComponent < grammar::NonterminalAlphabet > ( ).get ( ).count ( symbol ) ) - throw grammar::GrammarException ( "Symbol " + ( std::string ) symbol + "cannot be in terminal alphabet since it is already nonterminal alphabet" ); - } -}; - -template < > -class ComponentConstraint2< grammar::EpsilonFreeCFG, alphabet::Symbol, grammar::NonterminalAlphabet > { -public: - static bool used ( const grammar::EpsilonFreeCFG & grammar, const alphabet::Symbol & symbol ) { - for ( const std::pair < const alphabet::Symbol, std::set < std::vector < alphabet::Symbol > > > & rule : grammar.getRules ( ) ) { - if ( rule.first == symbol ) - return true; - - for ( const std::vector < alphabet::Symbol > & rhs : rule.second ) - if ( std::find ( rhs.begin ( ), rhs.end ( ), symbol ) != rhs.end ( ) ) - return true; - - } - - if ( grammar.accessElement < grammar::InitialSymbol > ( ).get ( ) == symbol ) - return true; - - return false; - } - - static bool available ( const grammar::EpsilonFreeCFG &, const alphabet::Symbol & ) { - return true; - } - - static void valid ( const grammar::EpsilonFreeCFG & grammar, const alphabet::Symbol & symbol ) { - if ( grammar.accessComponent < grammar::TerminalAlphabet > ( ).get ( ).count ( symbol ) ) - throw grammar::GrammarException ( "Symbol " + ( std::string ) symbol + "cannot be in nonterminal alphabet since it is already in terminal alphabet" ); - } -}; - -template < > -class ElementConstraint2< grammar::EpsilonFreeCFG, alphabet::Symbol, grammar::InitialSymbol > { -public: - static bool available ( const grammar::EpsilonFreeCFG & grammar, const alphabet::Symbol & symbol ) { - return grammar.accessComponent < grammar::NonterminalAlphabet > ( ).get ( ).count ( symbol ); - } - - static void valid ( const grammar::EpsilonFreeCFG &, const alphabet::Symbol & ) { - } -}; - -} /* namespace std */ - namespace alib { auto EpsilonFreeCFGParserRegister = xmlApi < grammar::Grammar >::ParserRegister < grammar::EpsilonFreeCFG > ( ); diff --git a/alib2data/src/grammar/ContextFree/EpsilonFreeCFG.h b/alib2data/src/grammar/ContextFree/EpsilonFreeCFG.h index a7d6c2030492d23283c421622a493a8bd6bfaeea..867a8d15949e43559a8313ff5ae0eaafdbfc19cd 100644 --- a/alib2data/src/grammar/ContextFree/EpsilonFreeCFG.h +++ b/alib2data/src/grammar/ContextFree/EpsilonFreeCFG.h @@ -8,6 +8,7 @@ #ifndef EPSILON_FREE_CFG_H_ #define EPSILON_FREE_CFG_H_ +#include "../GrammarException.h" #include "../GrammarBase.h" #include <map> #include <vector> @@ -110,4 +111,71 @@ public: } /* namespace grammar */ +namespace std { + +template < > +class ComponentConstraint2< grammar::EpsilonFreeCFG, alphabet::Symbol, grammar::TerminalAlphabet > { +public: + static bool used ( const grammar::EpsilonFreeCFG & grammar, const alphabet::Symbol & symbol ) { + for ( const std::pair < const alphabet::Symbol, std::set < std::vector < alphabet::Symbol > > > & rule : grammar.getRules ( ) ) + for ( const std::vector < alphabet::Symbol > & rhs : rule.second ) + if ( std::find ( rhs.begin ( ), rhs.end ( ), symbol ) != rhs.end ( ) ) + return true; + + return false; + } + + static bool available ( const grammar::EpsilonFreeCFG &, const alphabet::Symbol & ) { + return true; + } + + static void valid ( const grammar::EpsilonFreeCFG & grammar, const alphabet::Symbol & symbol ) { + if ( grammar.accessComponent < grammar::NonterminalAlphabet > ( ).get ( ).count ( symbol ) ) + throw grammar::GrammarException ( "Symbol " + ( std::string ) symbol + "cannot be in terminal alphabet since it is already nonterminal alphabet" ); + } +}; + +template < > +class ComponentConstraint2< grammar::EpsilonFreeCFG, alphabet::Symbol, grammar::NonterminalAlphabet > { +public: + static bool used ( const grammar::EpsilonFreeCFG & grammar, const alphabet::Symbol & symbol ) { + for ( const std::pair < const alphabet::Symbol, std::set < std::vector < alphabet::Symbol > > > & rule : grammar.getRules ( ) ) { + if ( rule.first == symbol ) + return true; + + for ( const std::vector < alphabet::Symbol > & rhs : rule.second ) + if ( std::find ( rhs.begin ( ), rhs.end ( ), symbol ) != rhs.end ( ) ) + return true; + + } + + if ( grammar.accessElement < grammar::InitialSymbol > ( ).get ( ) == symbol ) + return true; + + return false; + } + + static bool available ( const grammar::EpsilonFreeCFG &, const alphabet::Symbol & ) { + return true; + } + + static void valid ( const grammar::EpsilonFreeCFG & grammar, const alphabet::Symbol & symbol ) { + if ( grammar.accessComponent < grammar::TerminalAlphabet > ( ).get ( ).count ( symbol ) ) + throw grammar::GrammarException ( "Symbol " + ( std::string ) symbol + "cannot be in nonterminal alphabet since it is already in terminal alphabet" ); + } +}; + +template < > +class ElementConstraint2< grammar::EpsilonFreeCFG, alphabet::Symbol, grammar::InitialSymbol > { +public: + static bool available ( const grammar::EpsilonFreeCFG & grammar, const alphabet::Symbol & symbol ) { + return grammar.accessComponent < grammar::NonterminalAlphabet > ( ).get ( ).count ( symbol ); + } + + static void valid ( const grammar::EpsilonFreeCFG &, const alphabet::Symbol & ) { + } +}; + +} /* namespace std */ + #endif /* EPSILON_FREE_CFG_H_ */ diff --git a/alib2data/src/grammar/ContextFree/GNF.cpp b/alib2data/src/grammar/ContextFree/GNF.cpp index fd5dc410795acec28c234df330bf765af02ed559..70cf0ce64e3537043a4b23174935cb5ae82751ee 100644 --- a/alib2data/src/grammar/ContextFree/GNF.cpp +++ b/alib2data/src/grammar/ContextFree/GNF.cpp @@ -6,7 +6,6 @@ */ #include "GNF.h" -#include "../GrammarException.h" #include <algorithm> #include <sstream> @@ -191,72 +190,6 @@ void GNF::composeRules ( std::deque < sax::Token > & out ) const { } /* namespace grammar */ -namespace std { - -template < > -class ComponentConstraint2< grammar::GNF, alphabet::Symbol, grammar::TerminalAlphabet > { -public: - static bool used ( const grammar::GNF & grammar, const alphabet::Symbol & symbol ) { - for ( const std::pair < const alphabet::Symbol, std::set < std::pair < alphabet::Symbol, std::vector < alphabet::Symbol > > > > & rule : grammar.getRules ( ) ) - for ( const std::pair < alphabet::Symbol, std::vector < alphabet::Symbol > > & rhs : rule.second ) - if ( rhs.first == symbol ) - return true; - - return false; - } - - static bool available ( const grammar::GNF &, const alphabet::Symbol & ) { - return true; - } - - static void valid ( const grammar::GNF & grammar, const alphabet::Symbol & symbol ) { - if ( grammar.accessComponent < grammar::NonterminalAlphabet > ( ).get ( ).count ( symbol ) ) - throw grammar::GrammarException ( "Symbol " + ( std::string ) symbol + "cannot be in terminal alphabet since it is already nonterminal alphabet" ); - } -}; - -template < > -class ComponentConstraint2< grammar::GNF, alphabet::Symbol, grammar::NonterminalAlphabet > { -public: - static bool used ( const grammar::GNF & grammar, const alphabet::Symbol & symbol ) { - for ( const std::pair < const alphabet::Symbol, std::set < std::pair < alphabet::Symbol, std::vector < alphabet::Symbol > > > > & rule : grammar.getRules ( ) ) { - if ( rule.first == symbol ) - return true; - - for ( const std::pair < alphabet::Symbol, std::vector < alphabet::Symbol > > & rhs : rule.second ) - if ( std::find ( rhs.second.begin ( ), rhs.second.end ( ), symbol ) != rhs.second.end ( ) ) - return true; - } - - if ( grammar.accessElement < grammar::InitialSymbol > ( ).get ( ) == symbol ) - return true; - - return false; - } - - static bool available ( const grammar::GNF &, const alphabet::Symbol & ) { - return true; - } - - static void valid ( const grammar::GNF & grammar, const alphabet::Symbol & symbol ) { - if ( grammar.accessComponent < grammar::TerminalAlphabet > ( ).get ( ).count ( symbol ) ) - throw grammar::GrammarException ( "Symbol " + ( std::string ) symbol + "cannot be in nonterminal alphabet since it is already in terminal alphabet" ); - } -}; - -template < > -class ElementConstraint2< grammar::GNF, alphabet::Symbol, grammar::InitialSymbol > { -public: - static bool available ( const grammar::GNF & grammar, const alphabet::Symbol & symbol ) { - return grammar.accessComponent < grammar::NonterminalAlphabet > ( ).get ( ).count ( symbol ); - } - - static void valid ( const grammar::GNF &, const alphabet::Symbol & ) { - } -}; - -} /* namespace std */ - namespace alib { auto GNFParserRegister = xmlApi < grammar::Grammar >::ParserRegister < grammar::GNF > ( ); diff --git a/alib2data/src/grammar/ContextFree/GNF.h b/alib2data/src/grammar/ContextFree/GNF.h index 73bff6619e83bb3f5e94c3bd52c7e898b153f31b..3e1bce6405615b80e6f371bdc92a849f976001b1 100644 --- a/alib2data/src/grammar/ContextFree/GNF.h +++ b/alib2data/src/grammar/ContextFree/GNF.h @@ -8,6 +8,7 @@ #ifndef GNF_H_ #define GNF_H_ +#include "../GrammarException.h" #include "../GrammarBase.h" #include <map> #include <vector> @@ -111,4 +112,70 @@ public: } /* namespace grammar */ +namespace std { + +template < > +class ComponentConstraint2< grammar::GNF, alphabet::Symbol, grammar::TerminalAlphabet > { +public: + static bool used ( const grammar::GNF & grammar, const alphabet::Symbol & symbol ) { + for ( const std::pair < const alphabet::Symbol, std::set < std::pair < alphabet::Symbol, std::vector < alphabet::Symbol > > > > & rule : grammar.getRules ( ) ) + for ( const std::pair < alphabet::Symbol, std::vector < alphabet::Symbol > > & rhs : rule.second ) + if ( rhs.first == symbol ) + return true; + + return false; + } + + static bool available ( const grammar::GNF &, const alphabet::Symbol & ) { + return true; + } + + static void valid ( const grammar::GNF & grammar, const alphabet::Symbol & symbol ) { + if ( grammar.accessComponent < grammar::NonterminalAlphabet > ( ).get ( ).count ( symbol ) ) + throw grammar::GrammarException ( "Symbol " + ( std::string ) symbol + "cannot be in terminal alphabet since it is already nonterminal alphabet" ); + } +}; + +template < > +class ComponentConstraint2< grammar::GNF, alphabet::Symbol, grammar::NonterminalAlphabet > { +public: + static bool used ( const grammar::GNF & grammar, const alphabet::Symbol & symbol ) { + for ( const std::pair < const alphabet::Symbol, std::set < std::pair < alphabet::Symbol, std::vector < alphabet::Symbol > > > > & rule : grammar.getRules ( ) ) { + if ( rule.first == symbol ) + return true; + + for ( const std::pair < alphabet::Symbol, std::vector < alphabet::Symbol > > & rhs : rule.second ) + if ( std::find ( rhs.second.begin ( ), rhs.second.end ( ), symbol ) != rhs.second.end ( ) ) + return true; + } + + if ( grammar.accessElement < grammar::InitialSymbol > ( ).get ( ) == symbol ) + return true; + + return false; + } + + static bool available ( const grammar::GNF &, const alphabet::Symbol & ) { + return true; + } + + static void valid ( const grammar::GNF & grammar, const alphabet::Symbol & symbol ) { + if ( grammar.accessComponent < grammar::TerminalAlphabet > ( ).get ( ).count ( symbol ) ) + throw grammar::GrammarException ( "Symbol " + ( std::string ) symbol + "cannot be in nonterminal alphabet since it is already in terminal alphabet" ); + } +}; + +template < > +class ElementConstraint2< grammar::GNF, alphabet::Symbol, grammar::InitialSymbol > { +public: + static bool available ( const grammar::GNF & grammar, const alphabet::Symbol & symbol ) { + return grammar.accessComponent < grammar::NonterminalAlphabet > ( ).get ( ).count ( symbol ); + } + + static void valid ( const grammar::GNF &, const alphabet::Symbol & ) { + } +}; + +} /* namespace std */ + #endif /* GNF_H_ */ diff --git a/alib2data/src/grammar/ContextFree/LG.cpp b/alib2data/src/grammar/ContextFree/LG.cpp index 418e2f9f86154026634ce274a28e9e5e2763c35f..2a9ca5aa1d70c79d589830416c4b4311137ee523 100644 --- a/alib2data/src/grammar/ContextFree/LG.cpp +++ b/alib2data/src/grammar/ContextFree/LG.cpp @@ -6,7 +6,6 @@ */ #include "LG.h" -#include "../GrammarException.h" #include <algorithm> #include <sstream> @@ -218,95 +217,6 @@ void LG::composeRules ( std::deque < sax::Token > & out ) const { } /* namespace grammar */ -namespace std { - -template < > -class ComponentConstraint2< grammar::LG, alphabet::Symbol, grammar::TerminalAlphabet > { -public: - static bool used ( const grammar::LG & grammar, const alphabet::Symbol & symbol ) { - for ( const std::pair < const alphabet::Symbol, std::set < std::variant < std::vector < alphabet::Symbol >, std::tuple < std::vector < alphabet::Symbol >, alphabet::Symbol, std::vector < alphabet::Symbol > > > > > & rule : grammar.getRules ( ) ) { - for ( const std::variant < std::vector < alphabet::Symbol >, std::tuple < std::vector < alphabet::Symbol >, alphabet::Symbol, std::vector < alphabet::Symbol > > > & rhsTmp : rule.second ) - if ( rhsTmp.is < std::vector < alphabet::Symbol > > ( ) ) { - const std::vector < alphabet::Symbol > & rhs = rhsTmp.get < std::vector < alphabet::Symbol > > ( ); - - if ( std::find ( rhs.begin ( ), rhs.end ( ), symbol ) != rhs.end ( ) ) - return true; - } else { - const std::tuple < std::vector < alphabet::Symbol >, alphabet::Symbol, std::vector < alphabet::Symbol > > & rhs = rhsTmp.get < std::tuple < std::vector < alphabet::Symbol >, alphabet::Symbol, std::vector < alphabet::Symbol > > > ( ); - - const std::vector < alphabet::Symbol > & lPart = std::get < 0 > ( rhs ); - - if ( std::find ( lPart.begin ( ), lPart.end ( ), symbol ) != lPart.end ( ) ) - return true; - - const std::vector < alphabet::Symbol > & rPart = std::get < 2 > ( rhs ); - - if ( std::find ( rPart.begin ( ), rPart.end ( ), symbol ) != rPart.end ( ) ) - return true; - } - - } - - return false; - } - - static bool available ( const grammar::LG &, const alphabet::Symbol & ) { - return true; - } - - static void valid ( const grammar::LG & grammar, const alphabet::Symbol & symbol ) { - if ( grammar.accessComponent < grammar::NonterminalAlphabet > ( ).get ( ).count ( symbol ) ) - throw grammar::GrammarException ( "Symbol " + ( std::string ) symbol + "cannot be in terminal alphabet since it is already nonterminal alphabet" ); - } -}; - -template < > -class ComponentConstraint2< grammar::LG, alphabet::Symbol, grammar::NonterminalAlphabet > { -public: - static bool used ( const grammar::LG & grammar, const alphabet::Symbol & symbol ) { - for ( const std::pair < const alphabet::Symbol, std::set < std::variant < std::vector < alphabet::Symbol >, std::tuple < std::vector < alphabet::Symbol >, alphabet::Symbol, std::vector < alphabet::Symbol > > > > > & rule : grammar.getRules ( ) ) { - if ( rule.first == symbol ) - return true; - - for ( const std::variant < std::vector < alphabet::Symbol >, std::tuple < std::vector < alphabet::Symbol >, alphabet::Symbol, std::vector < alphabet::Symbol > > > & rhsTmp : rule.second ) - if ( rhsTmp.is < std::tuple < std::vector < alphabet::Symbol >, alphabet::Symbol, std::vector < alphabet::Symbol > > > ( ) ) { - const std::tuple < std::vector < alphabet::Symbol >, alphabet::Symbol, std::vector < alphabet::Symbol > > & rhs = rhsTmp.get < std::tuple < std::vector < alphabet::Symbol >, alphabet::Symbol, std::vector < alphabet::Symbol > > > ( ); - - if ( std::get < 1 > ( rhs ) == symbol ) - return true; - } - - } - - if ( grammar.accessElement < grammar::InitialSymbol > ( ).get ( ) == symbol ) - return true; - - return false; - } - - static bool available ( const grammar::LG &, const alphabet::Symbol & ) { - return true; - } - - static void valid ( const grammar::LG & grammar, const alphabet::Symbol & symbol ) { - if ( grammar.accessComponent < grammar::TerminalAlphabet > ( ).get ( ).count ( symbol ) ) - throw grammar::GrammarException ( "Symbol " + ( std::string ) symbol + "cannot be in nonterminal alphabet since it is already in terminal alphabet" ); - } -}; - -template < > -class ElementConstraint2< grammar::LG, alphabet::Symbol, grammar::InitialSymbol > { -public: - static bool available ( const grammar::LG & grammar, const alphabet::Symbol & symbol ) { - return grammar.accessComponent < grammar::NonterminalAlphabet > ( ).get ( ).count ( symbol ); - } - - static void valid ( const grammar::LG &, const alphabet::Symbol & ) { - } -}; - -} /* namespace std */ - namespace alib { auto LGParserRegister = xmlApi < grammar::Grammar >::ParserRegister < grammar::LG > ( ); diff --git a/alib2data/src/grammar/ContextFree/LG.h b/alib2data/src/grammar/ContextFree/LG.h index 54b322f591d5c7672a456614f78b49cb13434a7b..81c9d23697025e58b8cab65c0fc1899471211dd2 100644 --- a/alib2data/src/grammar/ContextFree/LG.h +++ b/alib2data/src/grammar/ContextFree/LG.h @@ -8,6 +8,7 @@ #ifndef LG_H_ #define LG_H_ +#include "../GrammarException.h" #include "../GrammarBase.h" #include <map> #include <tuple> @@ -112,4 +113,93 @@ public: } /* namespace grammar */ +namespace std { + +template < > +class ComponentConstraint2< grammar::LG, alphabet::Symbol, grammar::TerminalAlphabet > { +public: + static bool used ( const grammar::LG & grammar, const alphabet::Symbol & symbol ) { + for ( const std::pair < const alphabet::Symbol, std::set < std::variant < std::vector < alphabet::Symbol >, std::tuple < std::vector < alphabet::Symbol >, alphabet::Symbol, std::vector < alphabet::Symbol > > > > > & rule : grammar.getRules ( ) ) { + for ( const std::variant < std::vector < alphabet::Symbol >, std::tuple < std::vector < alphabet::Symbol >, alphabet::Symbol, std::vector < alphabet::Symbol > > > & rhsTmp : rule.second ) + if ( rhsTmp.is < std::vector < alphabet::Symbol > > ( ) ) { + const std::vector < alphabet::Symbol > & rhs = rhsTmp.get < std::vector < alphabet::Symbol > > ( ); + + if ( std::find ( rhs.begin ( ), rhs.end ( ), symbol ) != rhs.end ( ) ) + return true; + } else { + const std::tuple < std::vector < alphabet::Symbol >, alphabet::Symbol, std::vector < alphabet::Symbol > > & rhs = rhsTmp.get < std::tuple < std::vector < alphabet::Symbol >, alphabet::Symbol, std::vector < alphabet::Symbol > > > ( ); + + const std::vector < alphabet::Symbol > & lPart = std::get < 0 > ( rhs ); + + if ( std::find ( lPart.begin ( ), lPart.end ( ), symbol ) != lPart.end ( ) ) + return true; + + const std::vector < alphabet::Symbol > & rPart = std::get < 2 > ( rhs ); + + if ( std::find ( rPart.begin ( ), rPart.end ( ), symbol ) != rPart.end ( ) ) + return true; + } + + } + + return false; + } + + static bool available ( const grammar::LG &, const alphabet::Symbol & ) { + return true; + } + + static void valid ( const grammar::LG & grammar, const alphabet::Symbol & symbol ) { + if ( grammar.accessComponent < grammar::NonterminalAlphabet > ( ).get ( ).count ( symbol ) ) + throw grammar::GrammarException ( "Symbol " + ( std::string ) symbol + "cannot be in terminal alphabet since it is already nonterminal alphabet" ); + } +}; + +template < > +class ComponentConstraint2< grammar::LG, alphabet::Symbol, grammar::NonterminalAlphabet > { +public: + static bool used ( const grammar::LG & grammar, const alphabet::Symbol & symbol ) { + for ( const std::pair < const alphabet::Symbol, std::set < std::variant < std::vector < alphabet::Symbol >, std::tuple < std::vector < alphabet::Symbol >, alphabet::Symbol, std::vector < alphabet::Symbol > > > > > & rule : grammar.getRules ( ) ) { + if ( rule.first == symbol ) + return true; + + for ( const std::variant < std::vector < alphabet::Symbol >, std::tuple < std::vector < alphabet::Symbol >, alphabet::Symbol, std::vector < alphabet::Symbol > > > & rhsTmp : rule.second ) + if ( rhsTmp.is < std::tuple < std::vector < alphabet::Symbol >, alphabet::Symbol, std::vector < alphabet::Symbol > > > ( ) ) { + const std::tuple < std::vector < alphabet::Symbol >, alphabet::Symbol, std::vector < alphabet::Symbol > > & rhs = rhsTmp.get < std::tuple < std::vector < alphabet::Symbol >, alphabet::Symbol, std::vector < alphabet::Symbol > > > ( ); + + if ( std::get < 1 > ( rhs ) == symbol ) + return true; + } + + } + + if ( grammar.accessElement < grammar::InitialSymbol > ( ).get ( ) == symbol ) + return true; + + return false; + } + + static bool available ( const grammar::LG &, const alphabet::Symbol & ) { + return true; + } + + static void valid ( const grammar::LG & grammar, const alphabet::Symbol & symbol ) { + if ( grammar.accessComponent < grammar::TerminalAlphabet > ( ).get ( ).count ( symbol ) ) + throw grammar::GrammarException ( "Symbol " + ( std::string ) symbol + "cannot be in nonterminal alphabet since it is already in terminal alphabet" ); + } +}; + +template < > +class ElementConstraint2< grammar::LG, alphabet::Symbol, grammar::InitialSymbol > { +public: + static bool available ( const grammar::LG & grammar, const alphabet::Symbol & symbol ) { + return grammar.accessComponent < grammar::NonterminalAlphabet > ( ).get ( ).count ( symbol ); + } + + static void valid ( const grammar::LG &, const alphabet::Symbol & ) { + } +}; + +} /* namespace std */ + #endif /* LG_H_ */