From a4fd9c00605466ea35e6808b21d46b682c971c2d Mon Sep 17 00:00:00 2001 From: Jan Travnicek <Jan.Travnicek@fit.cvut.cz> Date: Mon, 1 Aug 2016 17:06:55 +0200 Subject: [PATCH] move updated constraints to header files --- alib2data/src/automaton/FSM/CompactNFA.cpp | 75 ------- alib2data/src/automaton/FSM/CompactNFA.h | 75 +++++++ alib2data/src/automaton/FSM/DFA.cpp | 75 ------- alib2data/src/automaton/FSM/DFA.h | 75 +++++++ alib2data/src/automaton/FSM/EpsilonNFA.cpp | 76 ------- alib2data/src/automaton/FSM/EpsilonNFA.h | 75 +++++++ alib2data/src/automaton/FSM/ExtendedNFA.cpp | 76 ------- alib2data/src/automaton/FSM/ExtendedNFA.h | 75 +++++++ .../automaton/FSM/MultiInitialStateNFA.cpp | 79 -------- .../src/automaton/FSM/MultiInitialStateNFA.h | 79 ++++++++ alib2data/src/automaton/FSM/NFA.cpp | 75 ------- alib2data/src/automaton/FSM/NFA.h | 75 +++++++ alib2data/src/automaton/PDA/DPDA.cpp | 111 ---------- alib2data/src/automaton/PDA/DPDA.h | 111 ++++++++++ .../src/automaton/PDA/InputDrivenDPDA.cpp | 111 ---------- alib2data/src/automaton/PDA/InputDrivenDPDA.h | 111 ++++++++++ .../src/automaton/PDA/InputDrivenNPDA.cpp | 111 ---------- alib2data/src/automaton/PDA/InputDrivenNPDA.h | 111 ++++++++++ alib2data/src/automaton/PDA/NPDA.cpp | 118 ----------- alib2data/src/automaton/PDA/NPDA.h | 118 +++++++++++ alib2data/src/automaton/PDA/NPDTA.cpp | 139 ------------- alib2data/src/automaton/PDA/NPDTA.h | 139 +++++++++++++ .../PDA/RealTimeHeightDeterministicDPDA.cpp | 128 ------------ .../PDA/RealTimeHeightDeterministicDPDA.h | 128 ++++++++++++ .../PDA/RealTimeHeightDeterministicNPDA.cpp | 148 -------------- .../PDA/RealTimeHeightDeterministicNPDA.h | 148 ++++++++++++++ alib2data/src/automaton/PDA/SinglePopDPDA.cpp | 108 ---------- alib2data/src/automaton/PDA/SinglePopDPDA.h | 108 ++++++++++ alib2data/src/automaton/PDA/SinglePopNPDA.cpp | 118 ----------- alib2data/src/automaton/PDA/SinglePopNPDA.h | 118 +++++++++++ .../src/automaton/PDA/VisiblyPushdownDPDA.cpp | 170 ---------------- .../src/automaton/PDA/VisiblyPushdownDPDA.h | 170 ++++++++++++++++ .../src/automaton/PDA/VisiblyPushdownNPDA.cpp | 190 ------------------ .../src/automaton/PDA/VisiblyPushdownNPDA.h | 190 ++++++++++++++++++ alib2data/src/automaton/TA/DFTA.cpp | 61 ------ alib2data/src/automaton/TA/DFTA.h | 61 ++++++ alib2data/src/automaton/TA/NFTA.cpp | 61 ------ alib2data/src/automaton/TA/NFTA.h | 61 ++++++ alib2data/src/automaton/TM/OneTapeDTM.cpp | 112 ----------- alib2data/src/automaton/TM/OneTapeDTM.h | 112 +++++++++++ alib2data/src/grammar/ContextFree/CFG.cpp | 68 ------- alib2data/src/grammar/ContextFree/CFG.h | 68 +++++++ alib2data/src/grammar/ContextFree/CNF.cpp | 68 ------- alib2data/src/grammar/ContextFree/CNF.h | 68 +++++++ .../grammar/ContextFree/EpsilonFreeCFG.cpp | 68 ------- .../src/grammar/ContextFree/EpsilonFreeCFG.h | 68 +++++++ alib2data/src/grammar/ContextFree/GNF.cpp | 67 ------ alib2data/src/grammar/ContextFree/GNF.h | 67 ++++++ alib2data/src/grammar/ContextFree/LG.cpp | 90 --------- alib2data/src/grammar/ContextFree/LG.h | 90 +++++++++ 50 files changed, 2501 insertions(+), 2503 deletions(-) diff --git a/alib2data/src/automaton/FSM/CompactNFA.cpp b/alib2data/src/automaton/FSM/CompactNFA.cpp index 91cffbd844..c2eba0547d 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 d5beb074ca..5452ee8403 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 65773b1e44..676c9233e1 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 17a55b5fa8..0660b4680f 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 3da8e8985c..99ee59dffe 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 4fa7c5e910..2c767668c0 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 a0acd6a087..81ae24b425 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 8503db403c..996a107cce 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 c6df9881c0..371bb6cddc 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 c252e15b1a..2cd5835b42 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 5daa3d7eb8..9c2e9f68e8 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 8e9e180af8..e563d6222f 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 5458244e71..23918f00b9 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 39d0b84720..021bdb0b43 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 de733fa3a5..bed763e973 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 45b15a91cc..2584a7c9ca 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 2ebd78b3d8..abd4b6f1d0 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 6cb1609f77..393ebc8e7c 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 e5dbda5f32..c847bb3a72 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 4ad36c2696..7f44a8bcdc 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 632ec9510a..852b47a270 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 9e3bbbcb7d..224886688f 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 0417a37736..ca6199f3d7 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 d5fd1cc627..99ea87d1fa 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 be27a9d2a5..7ee296ef4a 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 fd10db0a0e..7944ab776d 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 798f22cc1f..72a521238d 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 fedeb6eecc..5f696fc48a 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 8f1ce76ca5..f2d609bd5a 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 3434a889c8..ae4d2d1b33 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 6c01077d60..62bcfbabfe 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 847f4c996f..69a4403138 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 847b661860..8eaed1f632 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 1ba58d8b78..85e4a77122 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 c0eb0a32f3..f5d166e84e 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 93d2cfd123..73b8c1c02b 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 e90e5958f0..d5271d46be 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 3e74762962..4ac94c13f0 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 88c4caf5e5..3b4cc1728b 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 fca58dab5d..c41aac391d 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 181d32d2ed..6d3aa43d00 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 5496edf78b..4b934db22c 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 fd6010f50e..94dc9a4adc 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 a835e9d205..b9c20afb8c 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 1a88fbf0a0..50d9a7abb7 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 a7d6c20304..867a8d1594 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 fd5dc41079..70cf0ce64e 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 73bff6619e..3e1bce6405 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 418e2f9f86..2a9ca5aa1d 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 54b322f591..81c9d23697 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_ */ -- GitLab