51 template <
class InputSymbolType,
class PushdownStoreSymbolType,
class StateType >
57 template <
class InputSymbolType,
class PushdownStoreSymbolType,
class StateType >
63 template <
class InputSymbolType,
class PushdownStoreSymbolType,
class StateType >
69 template <
class InputSymbolType,
class PushdownStoreSymbolType,
class StateType >
73template <
class InputSymbolType,
class PushdownStoreSymbolType,
class StateType >
78template <
class InputSymbolType,
class PushdownStoreSymbolType,
class StateType >
83template <
class InputSymbolType,
class PushdownStoreSymbolType,
class StateType >
91 for (
const auto & state : pda.
getStates ( ) )
92 res.addState ( state );
94 res.addFinalState ( state );
97 pushdownStoreAlphabet.insert ( alphabet::BottomOfTheStackSymbol::instance < InputSymbolType > ( ) );
98 res.setPushdownStoreAlphabet ( pushdownStoreAlphabet );
102 std::string us (
"us" );
106 const auto & to = transition.second;
108 if ( ( std::get < 2 > ( transition.first ).empty ( ) ) && ( to.second.empty ( ) ) ) {
109 res.addLocalTransition ( std::get < 0 > ( transition.first ), std::get < 1 > ( transition.first ), to.first );
110 }
else if ( ( std::get < 2 > ( transition.first ).size ( ) == 1 ) && ( to.second.empty ( ) ) ) {
111 res.addReturnTransition ( std::get < 0 > ( transition.first ), std::get < 1 > ( transition.first ), std::get < 2 > ( transition.first )[0], to.first );
112 }
else if ( ( std::get < 2 > ( transition.first ).empty ( ) ) && ( to.second.size ( ) == 1 ) ) {
113 res.addCallTransition ( std::get < 0 > ( transition.first ), std::get < 1 > ( transition.first ), to.first, to.second[0] );
115 int popPushIndex = 0;
116 int popPushSymbols = std::get < 2 > ( transition.first ).size ( ) + to.second.size ( );
119 for (
const InputSymbolType & pop :std::get < 2 > ( transition.first ) ) {
126 res.addState ( fromState );
127 res.addState ( toState );
129 if ( popPushIndex == 0 )
130 res.addReturnTransition ( fromState, std::get < 1 > ( transition.first ), pop, toState );
132 res.addReturnTransition ( fromState, pop, toState );
143 res.addState ( fromState );
144 res.addState ( toState );
146 if ( popPushIndex == 0 )
147 res.addCallTransition ( fromState, std::get < 1 > ( transition.first ), toState, push );
149 res.addCallTransition ( fromState, toState, push );
159template <
class InputSymbolType,
class PushdownStoreSymbolType,
class StateType >
165 for (
const auto & state : pda.
getStates ( ) )
166 res.addState ( state );
168 res.addFinalState ( state );
171 pushdownStoreAlphabet.insert ( alphabet::BottomOfTheStackSymbol::instance < InputSymbolType > ( ) );
172 res.setPushdownStoreAlphabet ( pushdownStoreAlphabet );
176 res.addInitialState (
q0 );
180 std::string us (
"us" );
184 if ( ( std::get < 2 > ( transition.first ).empty ( ) ) && ( transition.second.second.empty ( ) ) ) {
185 res.addLocalTransition ( std::get < 0 > ( transition.first ), std::get < 1 > ( transition.first ), transition.second.first );
186 }
else if ( ( std::get < 2 > ( transition.first ).size ( ) == 1 ) && ( transition.second.second.empty ( ) ) ) {
187 res.addReturnTransition ( std::get < 0 > ( transition.first ), std::get < 1 > ( transition.first ), std::get < 2 > ( transition.first )[0], transition.second.first );
188 }
else if ( ( std::get < 2 > ( transition.first ).empty ( ) ) && ( transition.second.second.size ( ) == 1 ) ) {
189 res.addCallTransition ( std::get < 0 > ( transition.first ), std::get < 1 > ( transition.first ), transition.second.first, transition.second.second[0] );
191 int popPushIndex = 0;
192 int popPushSymbols = std::get < 2 > ( transition.first ).size ( ) + transition.second.second.size ( );
195 std::for_each ( std::get < 2 > ( transition.first ).begin ( ), std::get < 2 > ( transition.first ).end ( ), [&] (
const InputSymbolType & pop ) {
196 ext::variant < StateType, std::string > fromState = ( popPushIndex == 0 ) ? ext::variant < StateType, std::string > ( std::get < 0 > ( transition.first ) ) : ext::variant < StateType, std::string > ( lastUS );
198 if ( popPushIndex != 0 ) lastUS = common::createUnique ( us + ext::to_string ( ++i ), res.getStates ( ) );
200 ext::variant < StateType, std::string > toState = ( popPushIndex == popPushSymbols - 1 ) ? ext::variant < StateType, std::string > ( transition.second.first ) : ext::variant < StateType, std::string > ( lastUS );
202 res.addState ( fromState );
203 res.addState ( toState );
205 if ( popPushIndex == 0 )
206 res.addReturnTransition ( fromState, std::get < 1 > ( transition.first ), pop, toState );
208 res.addReturnTransition ( fromState, pop, toState );
212 std::for_each ( transition.second.second.rbegin ( ), transition.second.second.rend ( ), [&] (
const InputSymbolType & push ) {
213 ext::variant < StateType, std::string > fromState = ( popPushIndex == 0 ) ? ext::variant < StateType, std::string > ( std::get < 0 > ( transition.first ) ) : ext::variant < StateType, std::string > ( lastUS );
215 if ( popPushIndex != 0 ) lastUS = common::createUnique ( us + ext::to_string ( ++i ), res.getStates ( ) );
217 ext::variant < StateType, std::string > toState = ( popPushIndex == popPushSymbols - 1 ) ? ext::variant < StateType, std::string > ( transition.second.first ) : ext::variant < StateType, std::string > ( lastUS );
219 res.addState ( fromState );
220 res.addState ( toState );
222 if ( popPushIndex == 0 )
223 res.addCallTransition ( fromState, std::get < 1 > ( transition.first ), toState, push );
225 res.addCallTransition ( fromState, toState, push );
Deterministic pushdown automaton. Accepts subset of context free languages.
Definition: DPDA.h:78
const PushdownStoreSymbolType & getInitialSymbol() const &
Definition: DPDA.h:301
const ext::set< PushdownStoreSymbolType > & getPushdownStoreAlphabet() const &
Definition: DPDA.h:243
const ext::set< InputSymbolType > & getInputAlphabet() const &
Definition: DPDA.h:330
const ext::set< StateType > & getStates() const &
Definition: DPDA.h:145
const ext::map< ext::tuple< StateType, common::symbol_or_epsilon< InputSymbolType >, ext::vector< PushdownStoreSymbolType > >, ext::pair< StateType, ext::vector< PushdownStoreSymbolType > > > & getTransitions() const &
Definition: DPDA.h:682
const ext::set< StateType > & getFinalStates() const &
Definition: DPDA.h:194
const StateType & getInitialState() const &
Definition: DPDA.h:116
const PushdownStoreSymbolType & getInitialSymbol() const &
Definition: NPDA.h:304
const ext::set< StateType > & getFinalStates() const &
Definition: NPDA.h:197
const StateType & getInitialState() const &
Definition: NPDA.h:119
const ext::set< StateType > & getStates() const &
Definition: NPDA.h:148
const ext::multimap< ext::tuple< StateType, common::symbol_or_epsilon< InputSymbolType >, ext::vector< PushdownStoreSymbolType > >, ext::pair< StateType, ext::vector< PushdownStoreSymbolType > > > & getTransitions() const &
Definition: NPDA.h:644
const ext::set< InputSymbolType > & getInputAlphabet() const &
Definition: NPDA.h:333
const ext::set< PushdownStoreSymbolType > & getPushdownStoreAlphabet() const &
Definition: NPDA.h:246
Deterministic real time height deterministic pushdown automaton. Accepts subset of context free langu...
Definition: RealTimeHeightDeterministicDPDA.h:89
Nondeterministic real time height deterministic pushdown automaton. Accepts subset of context free la...
Definition: RealTimeHeightDeterministicNPDA.h:76
Implementation of the variant class allowing to store any type of those listed in the template parame...
Definition: variant.hpp:98
int i
Definition: AllEpsilonClosure.h:118
StateType q0
Definition: SingleInitialState.h:96
Definition: ToGrammar.h:31
T createUnique(T object, const Alphabets &... alphabets)
Definition: createUnique.hpp:46
reverser< T > make_reverse(T &&container)
Reverese adaptor construction function.
Definition: iterator.hpp:544
ContainerType< ResType > transform(const ContainerType< InType, Ts ... > &in, Callback transform)
In container tranformation of all elements according to the tranform.
Definition: algorithm.hpp:150
std::string to_string(const T &value)
To string method designated for objects that can be casted to string.
Definition: string.hpp:131