Algorithms Library Toolkit
A toolkit for algorithms, especially for algorithms on formal languages
DeterminizeIDPDAPart.hxx
Go to the documentation of this file.
1
6#include <ext/algorithm>
7
8#include <alib/deque>
9
11
12namespace automaton {
13
14namespace determinize {
15
16template < class InputSymbolType, class PushdownSymbolType, class StateType >
18 // 1, 4
19 ext::set < StateType > initialState;
20 initialState.insert ( npda.getInitialState ( ) );
22
23 res.setInputAlphabet ( npda.getInputAlphabet ( ) );
24 res.setPushdownStoreAlphabet ( npda.getPushdownStoreAlphabet ( ) );
25 res.setPushdownStoreOperations ( npda.getPushdownStoreOperations ( ) );
26
27 // 2
29 todo.push_back ( std::move ( initialState ) );
30
31 do {
32 // 3a, c
33 ext::set < StateType > state = std::move ( todo.front ( ) );
34 todo.pop_front ( );
35
36 // 3b
37 for ( const InputSymbolType & input : npda.getInputAlphabet ( ) ) {
39
40 for ( StateType nfaState : state ) {
41 auto range = npda.getTransitions ( ).equal_range ( ext::make_pair ( std::move ( nfaState ), input ) );
42
43 for ( auto & transition : range )
44 dfaState.insert ( transition.second );
45 }
46
47 // 4
48 bool existed = !res.addState ( dfaState );
49
50 if ( !existed ) todo.push_back ( dfaState );
51
52 // 3b
53 res.addTransition ( state, input, std::move ( dfaState ) );
54 }
55 } while ( !todo.empty ( ) );
56
57 // 5
58 const ext::set < StateType > & finalLabels = npda.getFinalStates();
59 for ( const ext::set < StateType > & dfaState : res.getStates ( ) )
60 if ( ! ext::excludes ( finalLabels.begin ( ), finalLabels.end ( ), dfaState.begin ( ), dfaState.end ( ) ) )
61 res.addFinalState ( dfaState );
62
63 return res;
64}
65
66} /* namespace determinize */
67
68} /* namespace automaton */
Deterministic input driven pushdown automaton. Accepts subset of context free languages.
Definition: InputDrivenDPDA.h:79
Nondeterministic input driven pushdown automaton. Accepts subset of context free languages.
Definition: InputDrivenNPDA.h:79
const PushdownStoreSymbolType & getInitialSymbol() const &
Definition: InputDrivenNPDA.h:316
const ext::map< InputSymbolType, ext::pair< ext::vector< PushdownStoreSymbolType >, ext::vector< PushdownStoreSymbolType > > > & getPushdownStoreOperations() const &
Definition: InputDrivenNPDA.h:614
const ext::set< InputSymbolType > & getInputAlphabet() const &
Definition: InputDrivenNPDA.h:345
const ext::multimap< ext::pair< StateType, InputSymbolType >, StateType > & getTransitions() const &
Definition: InputDrivenNPDA.h:661
const ext::set< StateType > & getFinalStates() const &
Definition: InputDrivenNPDA.h:209
const ext::set< PushdownStoreSymbolType > & getPushdownStoreAlphabet() const &
Definition: InputDrivenNPDA.h:258
const StateType & getInitialState() const &
Definition: InputDrivenNPDA.h:131
static automaton::DFA< SymbolType, StateType > determinize(const automaton::DFA< SymbolType, StateType > &automaton)
Definition: Determinize.h:276
Class extending the deque class from the standard library. Original reason is to allow printing of th...
Definition: deque.hpp:44
Definition: set.hpp:44
auto begin() &
Inherited behavior of begin for non-const instance.
Definition: set.hpp:99
auto end() &
Inherited behavior of end for non-const instance.
Definition: set.hpp:129
typename T::StateType StateType
Definition: ToGrammarLeftRG.h:64
return res
Definition: MinimizeByPartitioning.h:145
Definition: ToGrammar.h:31
auto range(Container &&cont) -> decltype(std::forward< Container >(cont).range())
Definition: range.hpp:247
bool excludes(InputIt1 first1, InputIt1 last1, InputIt2 first2, InputIt2 last2, Compare comp)
Tests two sorted ranges wheter all elements from the second are not present in the first.
Definition: algorithm.hpp:46
constexpr auto make_pair(T1 &&x, T2 &&y)
Definition: pair.hpp:79