Algorithms Library Toolkit
A toolkit for algorithms, especially for algorithms on formal languages
ToRegExpKleene.h
Go to the documentation of this file.
1
6/*
7 * This file is part of Algorithms library toolkit.
8 * Copyright (C) 2017 Jan Travnicek (jan.travnicek@fit.cvut.cz)
9
10 * Algorithms library toolkit is free software: you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation, either version 3 of the License, or
13 * (at your option) any later version.
14
15 * Algorithms library toolkit is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19
20 * You should have received a copy of the GNU General Public License
21 * along with Algorithms library toolkit. If not, see <http://www.gnu.org/licenses/>.
22 */
23
24#pragma once
25
27
28#include <automaton/FSM/DFA.h>
29#include <automaton/FSM/NFA.h>
33
38
40
42
43namespace automaton {
44
45namespace convert {
46
52public:
60 template < class SymbolType, class StateType >
62
66 template < class SymbolType, class StateType >
68
72 template < class SymbolType, class StateType >
74
78 template < class SymbolType, class StateType >
80
84 template < class SymbolType, class StateType >
86
87private:
98 template < class SymbolType, class StateType >
100
104 template < class SymbolType, class StateType >
105 static regexp::UnboundedRegExpStructure < SymbolType > RGetDefault ( const std::map < std::pair < StateType, StateType >, regexp::UnboundedRegExpStructure < SymbolType > > & R, const std::pair < StateType, StateType > & key );
106};
107
108template < class SymbolType, class StateType >
109regexp::UnboundedRegExpStructure < SymbolType > ToRegExpKleene::RGetDefault ( const std::map < std::pair < StateType, StateType >, regexp::UnboundedRegExpStructure < SymbolType > > & R, const std::pair < StateType, StateType > & key ) {
110 auto it = R.find ( key );
112}
113
114template < class SymbolType, class StateType >
117}
118
119template < class SymbolType, class StateType >
122}
123
124template < class SymbolType, class StateType >
127}
128
129template < class SymbolType, class StateType >
132}
133
134template < class SymbolType, class StateType >
136 std::vector < std::map < std::pair < StateType, StateType >, regexp::UnboundedRegExpStructure < SymbolType > > > R ( 1 );
137 size_t k = 0;
138
139 // initialize R [ 0 ]
140 for ( const StateType & a : automaton.getStates ( ) )
141 for ( const StateType & b : automaton.getStates ( ) )
142 R [ k ] [ std::make_pair ( a, b ) ] = transitionsToRegExp ( automaton, a, b );
143 k += 1;
144
145 // initialize R [ 1 ] ... R [ k ]
146 for ( const StateType & kState : automaton.getStates ( ) ) {
147 R.push_back ( std::map < std::pair < StateType, StateType >, regexp::UnboundedRegExpStructure < SymbolType > > ( ) );
148
149 for ( const StateType & a : automaton.getStates ( ) ) {
150 for ( const StateType & b : automaton.getStates ( ) ) {
151 // TODO regexp::RegExpConcatenate on unbounded - variadic parameter count
152
154 RGetDefault ( R [ k - 1 ], std::make_pair ( a, kState ) ),
156 regexp::transform::RegExpIterate::iterate ( RGetDefault ( R [ k - 1 ], std::make_pair ( kState, kState ) ) ),
157 RGetDefault ( R [ k - 1 ], std::make_pair ( kState, b ) ) ) );
158
159 R [ k ] [ std::make_pair ( a, b ) ] = regexp::simplify::RegExpOptimize::optimize ( regexp::transform::RegExpAlternate::alternate ( RGetDefault ( R [ k - 1 ], std::make_pair ( a, b ) ), re ) );
160 }
161 }
162
163 k += 1;
164 }
165
167 for ( const auto & i : automaton.getInitialStates ( ) ) {
168 for ( const auto & f : automaton.getFinalStates ( ) ) {
169 ret = regexp::transform::RegExpAlternate::alternate ( ret, RGetDefault ( R [ k - 1 ], std::make_pair ( i, f ) ) );
170 }
171 }
172
174}
175
176
177template < class SymbolType, class StateType >
180
181 if ( from == to )
183
184 for ( const auto & transition: automaton.getTransitionsFromState ( from ) ) {
185 if ( transition.second == to ) {
186 if ( transition.first.second.is_epsilon ( ) )
188 else
190 }
191 }
192
194}
195
196} /* namespace convert */
197
198} /* namespace automaton */
199
Deterministic finite automaton. Accepts regular languages.
Definition: DFA.h:71
Epsilon nondeterministic finite automaton. Accepts regular languages.
Definition: EpsilonNFA.h:74
Epsilon nondeterministic finite automaton. Accepts regular languages.
Definition: MultiInitialStateEpsilonNFA.h:75
Nondeterministic finite automaton with multiple initial states. Accepts regular languages.
Definition: MultiInitialStateNFA.h:69
Nondeterministic finite automaton. Accepts regular languages.
Definition: NFA.h:66
Definition: ToRegExpKleene.h:51
static regexp::UnboundedRegExp< SymbolType > convert(const automaton::DFA< SymbolType, StateType > &automaton)
Definition: ToRegExpKleene.h:115
Represents the empty expression in the regular expression. The node can't have any children.
Definition: UnboundedRegExpEmpty.h:41
Represents the epsilon expression in the regular expression. The node can't have any children.
Definition: UnboundedRegExpEpsilon.h:41
Represents unbounded regular expression structure. Regular expression is stored as a tree of Unbounde...
Definition: UnboundedRegExpStructure.h:47
Represents the symbol in the regular expression. The can't have any children.
Definition: UnboundedRegExpSymbol.h:42
Unbounded regular expression represents regular expression. It describes regular languages....
Definition: UnboundedRegExp.h:80
static regexp::UnboundedRegExp< SymbolType > optimize(const regexp::UnboundedRegExp< SymbolType > &regexp)
static regexp::FormalRegExp< SymbolType > alternate(const regexp::FormalRegExp< SymbolType > &first, const regexp::FormalRegExp< SymbolType > &second)
Definition: RegExpAlternate.h:57
static regexp::FormalRegExp< SymbolType > concatenate(const regexp::FormalRegExp< SymbolType > &first, const regexp::FormalRegExp< SymbolType > &second)
Definition: RegExpConcatenate.h:57
static regexp::FormalRegExp< SymbolType > iterate(const regexp::FormalRegExp< SymbolType > &regexp)
Definition: RegExpIterate.h:56
typename T::StateType StateType
Definition: ToGrammarLeftRG.h:64
p second
Definition: ToRegExpAlgebraic.h:126
ext::set< ext::pair< StateType, StateType > > ret(const ext::set< ext::pair< StateType, StateType > > &S, const DeterministicPushdownStoreSymbolType &pdaSymbol, const InputSymbolType &input, const N &nondeterministic)
Definition: RHDPDACommon.h:57
int i
Definition: AllEpsilonClosure.h:118
Definition: ToGrammar.h:31
Definition: converterCommon.hpp:8
constexpr auto make_pair(T1 &&x, T2 &&y)
Definition: pair.hpp:79