Algorithms Library Toolkit
A toolkit for algorithms, especially for algorithms on formal languages
RegExpOptimize.h
Go to the documentation of this file.
1
6#pragma once
7
8#include <ext/algorithm>
9#include <ext/iterator>
10
13
16
19
20namespace regexp {
21
22namespace simplify {
23
24/*
25 * Optimizes RegExp (or its subtree) using axioms defined in Melichar 2.87
26 * (A1 to A10) and Melichar 2.95(V1 through V6 and V8, V9, V10)
27 * All methods return new tree.
28 *
29 * List of optimization on nodes:
30 * - RegExpAlternation: A1, A2, A3, A4, A9, V2, V5, V6
31 * - RegExpConcatenation: A5, A6, A7, A8, V8, V9
32 * - RegExpIteration: A10, V1, V3, V4, V10
33 *
34 * Details: ( id : direction of optim. : optim )
35 * - A1 : -> : x + ( y + z ) = ( x + y ) + z = x + y + z
36 * - A2 : <- : x + y = y + x
37 * - A3 : -> : x + \0 = x
38 * - A4 : -> : x + x = x
39 * - A5 : -> : x(yz) = (xy)z = xyz
40 * - A6 : -> : \ex = x\e = x
41 * - A7 : -> : \0x = x\0 = \0
42 * - A8 : <- : x( y + z ) = xy + xz
43 * - A9 : <- : ( x + y )z = xz + yz
44 * - A10: <- : x* = \e + x*x
45 * - A11: <- : x* = ( \e + x )*
46 * - V1 : -> : \0* = \e
47 * - V2 : -> : x* + x = x*
48 * - V3 : -> : x** = x*
49 * - V4 : <- : ( x + y )* = (x*y*)*
50 * - V5 : <- : x*y = y + x*xy
51 * - V6 : <- : x*y = y + xx*y
52 * - V7 : : bleh
53 * - V8 : -> : if \e in h(x) => xx* = x*
54 * - V8R : -> : if \e in h(x) => x*x = x*
55 * - V9 : -> : (xy)*x = x(yx)*
56 * - V10: <- : ( x + y )* = ( x* + y* )*
57 *
58 * - X1 : -> : a* + \e = a*
59 */
61public:
62
72 template < class SymbolType >
74
78 template < class SymbolType >
80
84 template < class SymbolType >
85 static void optimize( regexp::UnboundedRegExpAlternation < SymbolType > & alt, bool recursive = true );
86
90 template < class SymbolType >
91 static void optimize( regexp::UnboundedRegExpConcatenation < SymbolType > & concat, bool recursive = true );
92
96 template < class SymbolType >
97 static void optimize( regexp::UnboundedRegExpIteration < SymbolType > & iter, bool recursive = true );
98
99 template < class SymbolType >
101 template < class SymbolType >
103 template < class SymbolType >
105private:
106 template < class SymbolType >
107 class Unbounded {
108 public:
115
137
139 };
140
141 template < class SymbolType >
143
144 template < class SymbolType >
146 template < class SymbolType >
148 template < class SymbolType >
150 template < class SymbolType >
152 template < class SymbolType >
154 template < class SymbolType >
156 template < class SymbolType >
158 template < class SymbolType >
160 template < class SymbolType >
162 template < class SymbolType >
164 template < class SymbolType >
166 template < class SymbolType >
168 template < class SymbolType >
170 template < class SymbolType >
172 template < class SymbolType >
174 template < class SymbolType >
176 template < class SymbolType >
178 template < class SymbolType >
180 template < class SymbolType >
182 template < class SymbolType >
184 template < class SymbolType >
186
187 template < class SymbolType >
189};
190
191template < class SymbolType >
194}
195
196template < class SymbolType >
198 ext::smart_ptr < FormalRegExpElement < SymbolType > > optimized = optimizeInner( regexp.getStructure ( ) );
199
201}
202
203template < class SymbolType >
206}
207
208template < class SymbolType >
211
212 return regexp::UnboundedRegExpStructure < SymbolType > ( std::move ( structure.getStructure ( ) ).template accept < ext::ptr_value < regexp::UnboundedRegExpElement < SymbolType > >, RegExpOptimize::Unbounded < SymbolType > > ( true ) );
213}
214
215} /* namespace simplify */
216
217} /* namespace regexp */
218
221
Class representing wrapper of dynamically allocated object behaving like rvalue reference.
Definition: ptr_value.hpp:40
Managed pointer simulating value like behavior.
Definition: memory.hpp:233
Definition: FormalRegExpElement.h:62
Represents formal regular expression structure. Regular expression is stored as a tree of FormalRegEx...
Definition: FormalRegExpStructure.h:45
Formal regular expression represents regular expression. It describes regular languages....
Definition: FormalRegExp.h:78
Represents the alternation operator in the regular expression. The node can have 0 to n children in l...
Definition: UnboundedRegExpAlternation.h:44
Represents the concatenation operator in the regular expression. The node can have 0 to n children in...
Definition: UnboundedRegExpConcatenation.h:44
Definition: UnboundedRegExpElement.h:62
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 the iteration operator in the regular expression. The node has exactly one child.
Definition: UnboundedRegExpIteration.h:43
Represents unbounded regular expression structure. Regular expression is stored as a tree of Unbounde...
Definition: UnboundedRegExpStructure.h:47
const UnboundedRegExpElement< SymbolType > & getStructure() const
Definition: UnboundedRegExpStructure.h:171
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
Definition: RegExpOptimize.h:60
static regexp::FormalRegExp< SymbolType > optimize(const regexp::FormalRegExp< SymbolType > &regexp)
static regexp::UnboundedRegExp< SymbolType > optimize(const regexp::UnboundedRegExp< SymbolType > &regexp)
static regexp::UnboundedRegExpStructure< SymbolType > optimize(const regexp::UnboundedRegExpStructure< SymbolType > &regexp)
static regexp::FormalRegExpStructure< SymbolType > optimize(const regexp::FormalRegExpStructure< SymbolType > &regexp)
constexpr auto visit(Visitor &&vis, Variants &&... vars)
Definition: variant.hpp:42
Definition: Node.cpp:11
Definition: ToAutomaton.h:15