Algorithms Library Toolkit
A toolkit for algorithms, especially for algorithms on formal languages
FormalRTEElement.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#include <alib/set>
28#include <ext/tree_base>
29#include <core/visitor.hpp>
30
31namespace rte {
32
33template < class SymbolType >
34class FormalRTEElement;
35template < class SymbolType >
36class FormalRTEAlternation;
37template < class SymbolType >
38class FormalRTEIteration;
39template < class SymbolType >
40class FormalRTESubstitution;
41template < class SymbolType >
42class FormalRTESymbolSubst;
43template < class SymbolType >
44class FormalRTESymbolAlphabet;
45template < class SymbolType >
46class FormalRTEEmpty;
47
53template < class SymbolType >
54class FormalRTEElement : public ext::BaseNode < FormalRTEElement < SymbolType > > {
55protected:
60 public:
61 virtual ~ConstVisitor ( ) noexcept = default;
62 virtual void visit ( const FormalRTEAlternation < SymbolType > & alternation ) = 0;
63 virtual void visit ( const FormalRTEIteration < SymbolType > & iteration ) = 0;
64 virtual void visit ( const FormalRTESubstitution < SymbolType > & substitution ) = 0;
65 virtual void visit ( const FormalRTESymbolAlphabet < SymbolType > & symbol ) = 0;
66 virtual void visit ( const FormalRTESymbolSubst < SymbolType > & symbol ) = 0;
67 virtual void visit ( const FormalRTEEmpty < SymbolType > & empty ) = 0;
68 };
69
70 class Visitor {
71 public:
72 virtual ~Visitor ( ) noexcept = default;
73 virtual void visit ( FormalRTEAlternation < SymbolType > & alternation ) = 0;
74 virtual void visit ( FormalRTEIteration < SymbolType > & iteration ) = 0;
75 virtual void visit ( FormalRTESubstitution < SymbolType > & substitution ) = 0;
76 virtual void visit ( FormalRTESymbolAlphabet < SymbolType > & symbol ) = 0;
77 virtual void visit ( FormalRTESymbolSubst < SymbolType > & symbol ) = 0;
78 virtual void visit ( FormalRTEEmpty < SymbolType > & empty ) = 0;
79 };
80
88 template < class ReturnType, class Visitorr, class ... Params >
89 class ConstVisitorContext : public core::VisitorContextAux < ReturnType, Visitorr, Params ... >, public FormalRTEElement::ConstVisitor {
90 public:
94 using core::VisitorContextAux < ReturnType, Visitorr, Params ... >::VisitorContextAux;
95
99 void visit ( const FormalRTEAlternation < SymbolType > & inherit ) override {
100 this->call ( inherit, std::make_index_sequence < sizeof ... ( Params ) > { } );
101 }
102
106 void visit ( const FormalRTEIteration < SymbolType > & inherit ) override {
107 this->call ( inherit, std::make_index_sequence < sizeof ... ( Params ) > { } );
108 }
109
113 void visit ( const FormalRTESubstitution < SymbolType > & inherit ) override {
114 this->call ( inherit, std::make_index_sequence < sizeof ... ( Params ) > { } );
115 }
116
120 void visit ( const FormalRTESymbolAlphabet < SymbolType > & inherit ) override {
121 this->call ( inherit, std::make_index_sequence < sizeof ... ( Params ) > { } );
122 }
123
127 void visit ( const FormalRTESymbolSubst < SymbolType > & inherit ) override {
128 this->call ( inherit, std::make_index_sequence < sizeof ... ( Params ) > { } );
129 }
130
134 void visit ( const FormalRTEEmpty < SymbolType > & inherit ) override {
135 this->call ( inherit, std::make_index_sequence < sizeof ... ( Params ) > { } );
136 }
137
138 };
139
147 template < class ReturnType, class Visitorr, class ... Params >
148 class VisitorContext : public core::VisitorContextAux < ReturnType, Visitorr, Params ... >, public FormalRTEElement::Visitor {
149 public:
153 using core::VisitorContextAux < ReturnType, Visitorr, Params ... >::VisitorContextAux;
154
158 void visit ( FormalRTEAlternation < SymbolType > & inherit ) override {
159 this->call ( inherit, std::make_index_sequence < sizeof ... ( Params ) > { } );
160 }
161
165 void visit ( FormalRTEIteration < SymbolType > & inherit ) override {
166 this->call ( inherit, std::make_index_sequence < sizeof ... ( Params ) > { } );
167 }
168
172 void visit ( FormalRTESubstitution < SymbolType > & inherit ) override {
173 this->call ( inherit, std::make_index_sequence < sizeof ... ( Params ) > { } );
174 }
175
179 void visit ( FormalRTESymbolAlphabet < SymbolType > & inherit ) override {
180 this->call ( inherit, std::make_index_sequence < sizeof ... ( Params ) > { } );
181 }
182
186 void visit ( FormalRTESymbolSubst < SymbolType > & inherit ) override {
187 this->call ( inherit, std::make_index_sequence < sizeof ... ( Params ) > { } );
188 }
189
193 void visit ( FormalRTEEmpty < SymbolType > & inherit ) override {
194 this->call ( inherit, std::make_index_sequence < sizeof ... ( Params ) > { } );
195 }
196 };
197
203 virtual void accept ( FormalRTEElement::ConstVisitor & visitor ) const = 0;
204
210 virtual void accept ( FormalRTEElement::Visitor & visitor ) = 0;
211
212public:
213 virtual FormalRTEElement < SymbolType > * clone ( ) const & = 0;
214
215 virtual FormalRTEElement < SymbolType > * clone ( ) && = 0;
216
228 template < class ReturnType, class Visitorr, class ... Params >
229 ReturnType accept ( Params && ... params ) const {
230 ConstVisitorContext < ReturnType, Visitorr, Params ... > context ( std::forward < Params > ( params ) ... );
231 accept ( context );
232 return context.getResult ( );
233 }
234
246 template < class ReturnType, class Visitorr, class ... Params >
247 ReturnType accept ( Params && ... params ) {
248 VisitorContext < ReturnType, Visitorr, Params ... > context ( std::forward < Params > ( params ) ... );
249 accept ( context );
250 return context.getResult ( );
251 }
252
259 virtual bool testSymbol ( const common::ranked_symbol < SymbolType > & symbol ) const = 0;
260
268
274 std::pair < ext::set < common::ranked_symbol < SymbolType > >, ext::set < common::ranked_symbol < SymbolType > > > computeMinimalAlphabets ( ) const;
275
283 virtual bool checkAlphabet ( const ext::set < common::ranked_symbol < SymbolType > > & alphabetF, const ext::set < common::ranked_symbol < SymbolType > > & alphabetK ) const = 0;
284
291
301 instance >> os;
302 return os;
303 }
304
310 virtual void operator >>( ext::ostream & ) const = 0;
311
321 virtual std::strong_ordering operator <=> ( const FormalRTEElement < SymbolType > & other ) const = 0;
322
332 virtual bool operator == ( const FormalRTEElement < SymbolType > & other ) const = 0;
333};
334
335template < class SymbolType >
336std::pair < ext::set < common::ranked_symbol < SymbolType > >, ext::set < common::ranked_symbol < SymbolType > > > FormalRTEElement < SymbolType >::computeMinimalAlphabets ( ) const {
339
340 computeMinimalAlphabet ( alphabetF, alphabetK );
341 return std::make_pair ( std::move ( alphabetF ), std::move ( alphabetK ) );
342}
343
344} /* namespace rte */
345
347
Definition: ranked_symbol.hpp:20
Class implementing an actual visitor interface to the visitor.
Definition: visitor.hpp:22
Base class for hierarchy of tree node types. The tree node types can be used to construct tree struct...
Definition: tree_base.hpp:20
Definition: ostream.h:14
Definition: set.hpp:44
Managed pointer simulating value like behavior.
Definition: memory.hpp:233
Represents the alternation operator in the regular tree expression. The node must have exactly two ch...
Definition: FormalRTEAlternation.h:44
Definition: FormalRTEElement.h:89
void visit(const FormalRTEAlternation< SymbolType > &inherit) override
Definition: FormalRTEElement.h:99
void visit(const FormalRTEIteration< SymbolType > &inherit) override
Definition: FormalRTEElement.h:106
void visit(const FormalRTESymbolSubst< SymbolType > &inherit) override
Definition: FormalRTEElement.h:127
void visit(const FormalRTESubstitution< SymbolType > &inherit) override
Definition: FormalRTEElement.h:113
void visit(const FormalRTESymbolAlphabet< SymbolType > &inherit) override
Definition: FormalRTEElement.h:120
void visit(const FormalRTEEmpty< SymbolType > &inherit) override
Definition: FormalRTEElement.h:134
Definition: FormalRTEElement.h:59
virtual void visit(const FormalRTEAlternation< SymbolType > &alternation)=0
virtual ~ConstVisitor() noexcept=default
Definition: FormalRTEElement.h:148
void visit(FormalRTEEmpty< SymbolType > &inherit) override
Definition: FormalRTEElement.h:193
void visit(FormalRTESymbolAlphabet< SymbolType > &inherit) override
Definition: FormalRTEElement.h:179
void visit(FormalRTEIteration< SymbolType > &inherit) override
Definition: FormalRTEElement.h:165
void visit(FormalRTESubstitution< SymbolType > &inherit) override
Definition: FormalRTEElement.h:172
void visit(FormalRTESymbolSubst< SymbolType > &inherit) override
Definition: FormalRTEElement.h:186
void visit(FormalRTEAlternation< SymbolType > &inherit) override
Definition: FormalRTEElement.h:158
Definition: FormalRTEElement.h:70
virtual ~Visitor() noexcept=default
Definition: FormalRTEElement.h:54
virtual bool checkAlphabet(const ext::set< common::ranked_symbol< SymbolType > > &alphabetF, const ext::set< common::ranked_symbol< SymbolType > > &alphabetK) const =0
virtual void operator>>(ext::ostream &) const =0
ReturnType accept(Params &&... params)
Definition: FormalRTEElement.h:247
virtual bool testSymbol(const common::ranked_symbol< SymbolType > &symbol) const =0
friend ext::ostream & operator<<(ext::ostream &os, const FormalRTEElement< SymbolType > &instance)
Definition: FormalRTEElement.h:300
std::pair< ext::set< common::ranked_symbol< SymbolType > >, ext::set< common::ranked_symbol< SymbolType > > > computeMinimalAlphabets() const
Definition: FormalRTEElement.h:336
virtual void computeMinimalAlphabet(ext::set< common::ranked_symbol< SymbolType > > &alphabetF, ext::set< common::ranked_symbol< SymbolType > > &alphabetK) const =0
virtual std::strong_ordering operator<=>(const FormalRTEElement< SymbolType > &other) const =0
Three way comparison helper method evaluating allowing possibly deeper comparison of this with other ...
virtual bool operator==(const FormalRTEElement< SymbolType > &other) const =0
Comparison helper method evaluating allowing possibly deeper comparison of this with other class of t...
virtual FormalRTEElement< SymbolType > * clone() const &=0
virtual ext::smart_ptr< FormalRTEElement< DefaultSymbolType > > normalize() &&=0
Traverses the rte tree and normalizes the symbols to DefaultSymbolType.
virtual void accept(FormalRTEElement::Visitor &visitor)=0
Accept method of the visitor pattern. This is where the actual type of this object is evaluated.
virtual void accept(FormalRTEElement::ConstVisitor &visitor) const =0
Accept method of the visitor pattern. This is where the actual type of this object is evaluated.
Represents the empty expression in the regular tree expression. The node can't have any children.
Definition: FormalRTEEmpty.h:40
Represents the iteration operator in the regular tree expression. The node has exactly one child.
Definition: FormalRTEIteration.h:45
Represents the concatenation operator in the regular tree expression. The node must have exactly two ...
Definition: FormalRTESubstitution.h:44
Represents the terminal symbol in the regular tree expression. The number of children must be the sam...
Definition: FormalRTESymbolAlphabet.h:44
Represents the substitution symbol in the regular tree expression. The node can't have any children.
Definition: FormalRTESymbolSubst.h:43
ext::set< ext::pair< StateType, StateType > > call(const ext::set< ext::pair< StateType, StateType > > &S, const InputSymbolType &input, const N &nondeterministic)
Definition: RHDPDACommon.h:94
typename T::SymbolType SymbolType
Definition: ReachableStates.h:176
Definition: normalize.hpp:10
constexpr auto make_pair(T1 &&x, T2 &&y)
Definition: pair.hpp:79
Definition: ToFTAGlushkov.h:22