Algorithms Library Toolkit
A toolkit for algorithms, especially for algorithms on formal languages
GlushkovFollow.h
Go to the documentation of this file.
1
6#pragma once
7
8#include <ext/iterator>
9
10#include <alib/set>
11
13
21
22#include "GlushkovFirst.h"
23#include "GlushkovLast.h"
24#include "GlushkovPos.h"
25
27
28namespace regexp {
29
36public:
42 template < class SymbolType >
44
45 template < class SymbolType >
46 class Unbounded {
47 public:
54 };
55
61 template < class SymbolType >
63
64 template < class SymbolType >
65 class Formal {
66 public:
73 };
74};
75
76template < class SymbolType >
78 return re.getRegExp ( ).getStructure ( ).template accept < ext::set < regexp::UnboundedRegExpSymbol < SymbolType > >, GlushkovFollow::Unbounded < SymbolType > > ( symbol );
79}
80
81template < class SymbolType >
83 auto iter = std::find_if ( node.getElements ( ).begin ( ), node.getElements ( ).end ( ), [ & ] ( const UnboundedRegExpElement < SymbolType > & element ) {
84 return element.template accept < bool, GlushkovPos::Unbounded < SymbolType > > ( symbolptr );
85 } );
86
87 if ( iter == node.getElements ( ).end ( ) )
88 throw exception::CommonException ( "GlushkovFollow::Unbounded < SymbolType >::visit(Alt)" );
89
90 return iter->template accept < ext::set < regexp::UnboundedRegExpSymbol < SymbolType > >, GlushkovFollow::Unbounded < SymbolType > > ( symbolptr );
91}
92
93template < class SymbolType >
98
99 for ( auto e = node.getElements ( ).begin ( ); e != node.getElements ( ).end ( ); e++ ) {
100 if ( ! e->template accept < bool, GlushkovPos::Unbounded < SymbolType > > ( symbolptr ) )
101 continue;
102
103 tmp = e->template accept < ext::set < regexp::UnboundedRegExpSymbol < SymbolType > >, GlushkovFollow::Unbounded < SymbolType > > ( symbolptr );
104 ret.insert ( tmp.begin ( ), tmp.end ( ) );
105
106 lastSet = e->template accept < ext::set < regexp::UnboundedRegExpSymbol < SymbolType > >, GlushkovLast::Unbounded < SymbolType > > ( );
107
108 if ( lastSet.find ( symbolptr ) != lastSet.end ( ) )
109 for ( auto f = next ( e ); f != node.getElements ( ).end ( ); f++ ) {
110 tmp = f->template accept < ext::set < regexp::UnboundedRegExpSymbol < SymbolType > >, GlushkovFirst::Unbounded < SymbolType > > ( );
111 ret.insert ( tmp.begin ( ), tmp.end ( ) );
112
114 break;
115 }
116
117 }
118
119 return ret;
120}
121
122template < class SymbolType >
124 ext::set < regexp::UnboundedRegExpSymbol < SymbolType > > ret = node.getElement ( ).template accept < ext::set < regexp::UnboundedRegExpSymbol < SymbolType > >, GlushkovFollow::Unbounded < SymbolType > > ( symbolptr );
125 ext::set < regexp::UnboundedRegExpSymbol < SymbolType > > lastSet = node.getElement ( ).template accept < ext::set < regexp::UnboundedRegExpSymbol < SymbolType > >, GlushkovLast::Unbounded < SymbolType > > ( );
126
127 if ( lastSet.find ( symbolptr ) != lastSet.end ( ) ) {
128 ext::set < regexp::UnboundedRegExpSymbol < SymbolType > > firstSet = node.getElement ( ).template accept < ext::set < regexp::UnboundedRegExpSymbol < SymbolType > >, GlushkovFirst::Unbounded < SymbolType > > ( );
129 ret.insert ( firstSet.begin ( ), firstSet.end ( ) );
130 }
131
132 return ret;
133}
134
135template < class SymbolType >
138}
139
140template < class SymbolType >
143}
144
145template < class SymbolType >
148}
149
150template < class SymbolType >
154 re.getRegExp ( ).getStructure ( ).template accept < void, GlushkovFollow::Formal < SymbolType > > ( currentFollow, res );
155 return res;
156}
157
158template < class SymbolType >
160 node.getLeftElement ( ).template accept < void, GlushkovFollow::Formal < SymbolType > > ( currentFollow, res );
161 node.getRightElement ( ).template accept < void, GlushkovFollow::Formal < SymbolType > > ( currentFollow, res );
162}
163
164template < class SymbolType >
166 ext::set < regexp::FormalRegExpSymbol < SymbolType > > leftFollow = node.getRightElement ( ).template accept < ext::set < regexp::FormalRegExpSymbol < SymbolType > >, GlushkovFirst::Formal < SymbolType > > ( );
168 leftFollow.insert ( currentFollow.begin ( ), currentFollow.end ( ) );
169 node.getLeftElement ( ).template accept < void, GlushkovFollow::Formal < SymbolType > > ( leftFollow, res );
170 node.getRightElement ( ).template accept < void, GlushkovFollow::Formal < SymbolType > > ( currentFollow, res );
171}
172
173template < class SymbolType >
175 ext::set < regexp::FormalRegExpSymbol < SymbolType > > newFollow = node.getElement ( ).template accept < ext::set < regexp::FormalRegExpSymbol < SymbolType > >, GlushkovFirst::Formal < SymbolType > > ( );
176 newFollow.insert ( currentFollow.begin ( ), currentFollow.end ( ) );
177 node.getElement ( ).template accept < void, GlushkovFollow::Formal < SymbolType > > ( newFollow, res );
178}
179
180template < class SymbolType >
182 res.insert ( std::make_pair ( node, currentFollow ) );
183}
184
185template < class SymbolType >
187}
188
189template < class SymbolType >
191}
192
193} /* namespace regexp */
194
Basic exception from which all other exceptions are derived.
Definition: CommonException.h:21
Class extending the map class from the standard library. Original reason is to allow printing of the ...
Definition: map.hpp:48
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
Represents the alternation operator in the regular expression. The node must have exactly two childre...
Definition: FormalRegExpAlternation.h:44
Represents the concatenation operator in the regular expression. The node must have exactly two child...
Definition: FormalRegExpConcatenation.h:44
Represents the empty expression in the regular expression. The node can't have any children.
Definition: FormalRegExpEmpty.h:41
Represents the epsilon expression in the regular expression. The node can't have any children.
Definition: FormalRegExpEpsilon.h:41
Represents the iteration operator in the regular expression. The node has exactly one child.
Definition: FormalRegExpIteration.h:44
Represents the symbol in the regular expression. The can't have any children.
Definition: FormalRegExpSymbol.h:42
Formal regular expression represents regular expression. It describes regular languages....
Definition: FormalRegExp.h:78
const FormalRegExpStructure< SymbolType > & getRegExp() const &
Definition: FormalRegExp.h:208
Definition: GlushkovFirst.h:57
Definition: GlushkovFirst.h:39
Definition: GlushkovFollow.h:65
static void visit(const regexp::FormalRegExpAlternation< SymbolType > &node, ext::set< regexp::FormalRegExpSymbol< SymbolType > > &currentFollow, ext::map< regexp::FormalRegExpSymbol< SymbolType >, ext::set< regexp::FormalRegExpSymbol< SymbolType > > > &res)
Definition: GlushkovFollow.h:159
Definition: GlushkovFollow.h:46
static ext::set< regexp::UnboundedRegExpSymbol< SymbolType > > visit(const regexp::UnboundedRegExpAlternation< SymbolType > &node, const regexp::UnboundedRegExpSymbol< SymbolType > &symbolptr)
Definition: GlushkovFollow.h:82
Definition: GlushkovFollow.h:35
static ext::set< UnboundedRegExpSymbol< SymbolType > > follow(const regexp::UnboundedRegExp< SymbolType > &re, const UnboundedRegExpSymbol< SymbolType > &symbol)
Definition: GlushkovFollow.h:77
Definition: GlushkovLast.h:39
Definition: GlushkovPos.h:34
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 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
const UnboundedRegExpStructure< SymbolType > & getRegExp() const &
Definition: UnboundedRegExp.h:210
static bool languageContainsEpsilon(const regexp::FormalRegExpElement< SymbolType > &regexp)
Definition: RegExpEpsilon.h:91
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
return res
Definition: MinimizeByPartitioning.h:145
constexpr auto make_pair(T1 &&x, T2 &&y)
Definition: pair.hpp:79
Definition: Node.cpp:11
Definition: ToAutomaton.h:15