Algorithms Library Toolkit
A toolkit for algorithms, especially for algorithms on formal languages
FormalRegExpElement.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
28namespace regexp {
29
30template < class SymbolType >
31class FormalRegExpElement;
32
33} /* namespace regexp */
34
35#include <alib/set>
36#include <ext/tree_base>
37#include <core/visitor.hpp>
38
39#include "../unbounded/UnboundedRegExpElement.h"
40
41namespace regexp {
42
43template < class SymbolType >
44class FormalRegExpAlternation;
45template < class SymbolType >
46class FormalRegExpConcatenation;
47template < class SymbolType >
48class FormalRegExpIteration;
49template < class SymbolType >
50class FormalRegExpSymbol;
51template < class SymbolType >
52class FormalRegExpEmpty;
53template < class SymbolType >
54class FormalRegExpEpsilon;
55
61template < class SymbolType >
62class FormalRegExpElement : public ext::BaseNode < FormalRegExpElement < SymbolType > > {
63protected:
67 class Visitor {
68 public:
69 virtual ~Visitor ( ) noexcept = default;
70 virtual void visit ( const FormalRegExpAlternation < SymbolType > & ) = 0;
71 virtual void visit ( const FormalRegExpConcatenation < SymbolType > & ) = 0;
72 virtual void visit ( const FormalRegExpIteration < SymbolType > & ) = 0;
73 virtual void visit ( const FormalRegExpSymbol < SymbolType > & ) = 0;
74 virtual void visit ( const FormalRegExpEmpty < SymbolType > & ) = 0;
75 virtual void visit ( const FormalRegExpEpsilon < SymbolType > & ) = 0;
76 };
77
85 template < class ReturnType, class Visitor, class ... Params >
86 class VisitorContext : public core::VisitorContextAux < ReturnType, Visitor, Params ... >, public FormalRegExpElement::Visitor {
87 public:
91 using core::VisitorContextAux < ReturnType, Visitor, Params ... >::VisitorContextAux;
92
96 void visit ( const FormalRegExpAlternation < SymbolType > & inherit ) override {
97 this->call ( inherit, std::make_index_sequence < sizeof ... ( Params ) > { } );
98 }
99
103 void visit ( const FormalRegExpConcatenation < SymbolType > & inherit ) override {
104 this->call ( inherit, std::make_index_sequence < sizeof ... ( Params ) > { } );
105 }
106
110 void visit ( const FormalRegExpIteration < SymbolType > & inherit ) override {
111 this->call ( inherit, std::make_index_sequence < sizeof ... ( Params ) > { } );
112 }
113
117 void visit ( const FormalRegExpSymbol < SymbolType > & inherit ) override {
118 this->call ( inherit, std::make_index_sequence < sizeof ... ( Params ) > { } );
119 }
120
124 void visit ( const FormalRegExpEmpty < SymbolType > & inherit ) override {
125 this->call ( inherit, std::make_index_sequence < sizeof ... ( Params ) > { } );
126 }
127
131 void visit ( const FormalRegExpEpsilon < SymbolType > & inherit ) override {
132 this->call ( inherit, std::make_index_sequence < sizeof ... ( Params ) > { } );
133 }
134 };
135
141 virtual void accept ( FormalRegExpElement::Visitor & visitor ) const = 0;
142
143public:
144 virtual FormalRegExpElement < SymbolType > * clone ( ) const & = 0;
145
146 virtual FormalRegExpElement < SymbolType > * clone ( ) && = 0;
147
159 template < class ReturnType, class Visitor, class ... Params >
160 ReturnType accept ( Params && ... params ) const {
161 VisitorContext < ReturnType, Visitor, Params ... > context ( std::forward < Params > ( params ) ... );
162 accept ( context );
163 return context.getResult ( );
164 }
165
172
179 virtual bool testSymbol ( const SymbolType & symbol ) const = 0;
180
187
194 virtual bool checkAlphabet ( const ext::set < SymbolType > & alphabet ) const = 0;
195
202
209
219 instance >> os;
220 return os;
221 }
222
228 virtual void operator >>( ext::ostream & ) const = 0;
229
239 virtual std::strong_ordering operator <=> ( const FormalRegExpElement < SymbolType > & other ) const = 0;
240
250 virtual bool operator == ( const FormalRegExpElement < SymbolType > & other ) const = 0;
251
252};
253
254template < class SymbolType >
257
259 return res;
260}
261
262} /* namespace regexp */
263
265
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 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
Definition: FormalRegExpElement.h:86
void visit(const FormalRegExpEmpty< SymbolType > &inherit) override
Definition: FormalRegExpElement.h:124
void visit(const FormalRegExpConcatenation< SymbolType > &inherit) override
Definition: FormalRegExpElement.h:103
void visit(const FormalRegExpSymbol< SymbolType > &inherit) override
Definition: FormalRegExpElement.h:117
void visit(const FormalRegExpIteration< SymbolType > &inherit) override
Definition: FormalRegExpElement.h:110
void visit(const FormalRegExpEpsilon< SymbolType > &inherit) override
Definition: FormalRegExpElement.h:131
void visit(const FormalRegExpAlternation< SymbolType > &inherit) override
Definition: FormalRegExpElement.h:96
Definition: FormalRegExpElement.h:67
virtual void visit(const FormalRegExpAlternation< SymbolType > &)=0
virtual ~Visitor() noexcept=default
Definition: FormalRegExpElement.h:62
virtual void accept(FormalRegExpElement::Visitor &visitor) const =0
Accept method of the visitor pattern. This is where the actual type of this object is evaluated.
virtual bool checkAlphabet(const ext::set< SymbolType > &alphabet) const =0
virtual ext::smart_ptr< UnboundedRegExpElement< SymbolType > > asUnbounded() const =0
virtual void operator>>(ext::ostream &) const =0
virtual ext::smart_ptr< FormalRegExpElement< DefaultSymbolType > > normalize() &&=0
Traverses the regexp tree and normalizes the symbols to DefaultSymbolType.
virtual std::strong_ordering operator<=>(const FormalRegExpElement< SymbolType > &other) const =0
Three way comparison helper method evaluating allowing possibly deeper comparison of this with other ...
virtual bool operator==(const FormalRegExpElement< SymbolType > &other) const =0
Comparison helper method evaluating allowing possibly deeper comparison of this with other class of t...
friend ext::ostream & operator<<(ext::ostream &os, const FormalRegExpElement< SymbolType > &instance)
Definition: FormalRegExpElement.h:218
virtual bool testSymbol(const SymbolType &symbol) const =0
virtual FormalRegExpElement< SymbolType > * clone() const &=0
virtual void computeMinimalAlphabet(ext::set< SymbolType > &alphabet) const =0
ext::set< SymbolType > computeMinimalAlphabet() const
Definition: FormalRegExpElement.h:255
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
Definition: BarSymbol.cpp:12
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
return res
Definition: MinimizeByPartitioning.h:145
Definition: normalize.hpp:10
Definition: ToAutomaton.h:15