Algorithms Library Toolkit
A toolkit for algorithms, especially for algorithms on formal languages
ToAutomatonDerivation.h
Go to the documentation of this file.
1
6#pragma once
7
10
11#include <automaton/FSM/DFA.h>
12
13#include <regexp/RegExp.h>
14
15#include <alib/set>
16#include <alib/deque>
17#include <alib/vector>
18
22
23namespace regexp {
24
25namespace convert {
26
32public:
43 template < class T, class SymbolType = typename T::symbol_type >
45};
46
47template < class T, class SymbolType >
49 // 1.
51
53
54 Qi.push_back ( V );
55
57 unsigned stateId = 0;
58 stateMap.insert ( std::make_pair ( V, stateId ++ ) );
59
61 automaton.setInputAlphabet(regexp.getAlphabet());
62
63 // 2., 3.
64 while(! Qi.empty()) {
65 T r = std::move ( Qi.back ( ) ); // initialize set Q_i
66 Qi.pop_back ( );
67
68 for(const auto& a : regexp.getAlphabet()) {
71
72 // this will also add \emptyset as a regexp (and as FA state)
73 if ( ! stateMap.contains ( derived ) ) { // if this state has already been found, do not add
74 Qi.push_back(derived);
75 automaton.addState ( stateId );
76 stateMap.insert ( std::make_pair ( derived, stateId ++ ) );
77
79 automaton.addFinalState(stateMap.at(derived));
80 }
81
82 automaton.addTransition(stateMap.at(r), a, stateMap.at(derived));
83 }
84 }
85
87 automaton.addFinalState(stateMap.at( V ));
88
89 return automaton;
90}
91
92} /* namespace convert */
93
94} /* namespace regexp */
Deterministic finite automaton. Accepts regular languages.
Definition: DFA.h:71
Class extending the deque class from the standard library. Original reason is to allow printing of th...
Definition: deque.hpp:44
Class extending the map class from the standard library. Original reason is to allow printing of the ...
Definition: map.hpp:48
R & at(const T &key, R &defaultValue)
Definition: map.hpp:163
std::pair< iterator, bool > insert(const T &key, const R &value)
Insert variant with explicit key and value parameters.
Definition: map.hpp:118
Definition: ToAutomatonDerivation.h:31
static automaton::DFA< SymbolType, unsigned > convert(const T &regexp)
Definition: ToAutomatonDerivation.h:48
static bool languageContainsEpsilon(const regexp::FormalRegExpElement< SymbolType > &regexp)
Definition: RegExpEpsilon.h:91
static regexp::UnboundedRegExp< SymbolType > optimize(const regexp::UnboundedRegExp< SymbolType > &regexp)
static regexp::FormalRegExp< SymbolType > derivation(const regexp::FormalRegExp< SymbolType > &regexp, const string::LinearString< SymbolType > &string)
Definition: RegExpDerivation.h:110
ext::deque< ext::set< StateType > > Qi
Definition: ReachableStates.h:95
Definition: ToGrammar.h:31
Definition: converterCommon.hpp:8
constexpr auto make_pair(T1 &&x, T2 &&y)
Definition: pair.hpp:79
Definition: ToAutomaton.h:15