Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
Algorithms Library Toolkit Core
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Container Registry
Model registry
Monitor
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Algorithms Library Toolkit
Algorithms Library Toolkit Core
Commits
c3860b98
Commit
c3860b98
authored
8 years ago
by
Jan Trávníček
Browse files
Options
Downloads
Patches
Plain Diff
template RegExpEpsilon algorithm
parent
422bd726
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
alib2algo/src/regexp/properties/RegExpEpsilon.cpp
+0
-84
0 additions, 84 deletions
alib2algo/src/regexp/properties/RegExpEpsilon.cpp
alib2algo/src/regexp/properties/RegExpEpsilon.h
+132
-18
132 additions, 18 deletions
alib2algo/src/regexp/properties/RegExpEpsilon.h
with
132 additions
and
102 deletions
alib2algo/src/regexp/properties/RegExpEpsilon.cpp
+
0
−
84
View file @
c3860b98
...
@@ -17,94 +17,10 @@ bool RegExpEpsilon::languageContainsEpsilon(const regexp::RegExp& regexp) {
...
@@ -17,94 +17,10 @@ bool RegExpEpsilon::languageContainsEpsilon(const regexp::RegExp& regexp) {
return
dispatch
(
regexp
.
getData
());
return
dispatch
(
regexp
.
getData
());
}
}
bool
RegExpEpsilon
::
languageContainsEpsilon
(
const
regexp
::
FormalRegExpElement
<
alphabet
::
Symbol
>
&
regexp
)
{
return
regexp
.
accept
<
bool
,
RegExpEpsilon
::
Formal
>
();
}
bool
RegExpEpsilon
::
languageContainsEpsilon
(
const
regexp
::
FormalRegExpStructure
<
alphabet
::
Symbol
>
&
regexp
)
{
return
languageContainsEpsilon
(
regexp
.
getStructure
());
}
bool
RegExpEpsilon
::
languageContainsEpsilon
(
const
regexp
::
FormalRegExp
<
>
&
regexp
)
{
return
languageContainsEpsilon
(
regexp
.
getRegExp
());
}
auto
RegExpEpsilonFormalRegExp
=
RegExpEpsilon
::
RegistratorWrapper
<
bool
,
regexp
::
FormalRegExp
<
>
>
(
RegExpEpsilon
::
languageContainsEpsilon
);
auto
RegExpEpsilonFormalRegExp
=
RegExpEpsilon
::
RegistratorWrapper
<
bool
,
regexp
::
FormalRegExp
<
>
>
(
RegExpEpsilon
::
languageContainsEpsilon
);
bool
RegExpEpsilon
::
languageContainsEpsilon
(
const
regexp
::
UnboundedRegExpElement
<
alphabet
::
Symbol
>
&
regexp
)
{
return
regexp
.
accept
<
bool
,
RegExpEpsilon
::
Unbounded
>
();
}
bool
RegExpEpsilon
::
languageContainsEpsilon
(
const
regexp
::
UnboundedRegExpStructure
<
alphabet
::
Symbol
>
&
regexp
)
{
return
languageContainsEpsilon
(
regexp
.
getStructure
());
}
bool
RegExpEpsilon
::
languageContainsEpsilon
(
const
regexp
::
UnboundedRegExp
<
>
&
regexp
)
{
return
languageContainsEpsilon
(
regexp
.
getRegExp
());
}
auto
RegExpEpsilonUnboundedRegExp
=
RegExpEpsilon
::
RegistratorWrapper
<
bool
,
regexp
::
UnboundedRegExp
<
>
>
(
RegExpEpsilon
::
languageContainsEpsilon
);
auto
RegExpEpsilonUnboundedRegExp
=
RegExpEpsilon
::
RegistratorWrapper
<
bool
,
regexp
::
UnboundedRegExp
<
>
>
(
RegExpEpsilon
::
languageContainsEpsilon
);
// ---------------------------------------------------------------------------
bool
RegExpEpsilon
::
Unbounded
::
visit
(
const
regexp
::
UnboundedRegExpAlternation
<
alphabet
::
Symbol
>
&
alternation
)
{
for
(
const
auto
&
element
:
alternation
.
getElements
(
)
)
if
(
element
->
accept
<
bool
,
RegExpEpsilon
::
Unbounded
>
(
)
)
return
true
;
return
false
;
}
bool
RegExpEpsilon
::
Unbounded
::
visit
(
const
regexp
::
UnboundedRegExpConcatenation
<
alphabet
::
Symbol
>
&
concatenation
)
{
for
(
const
auto
&
element
:
concatenation
.
getElements
(
)
)
if
(
!
element
->
accept
<
bool
,
RegExpEpsilon
::
Unbounded
>
(
)
)
return
false
;
return
true
;
}
bool
RegExpEpsilon
::
Unbounded
::
visit
(
const
regexp
::
UnboundedRegExpIteration
<
alphabet
::
Symbol
>
&
)
{
return
true
;
}
bool
RegExpEpsilon
::
Unbounded
::
visit
(
const
regexp
::
UnboundedRegExpSymbol
<
alphabet
::
Symbol
>
&
)
{
return
false
;
}
bool
RegExpEpsilon
::
Unbounded
::
visit
(
const
regexp
::
UnboundedRegExpEpsilon
<
alphabet
::
Symbol
>
&
)
{
return
true
;
}
bool
RegExpEpsilon
::
Unbounded
::
visit
(
const
regexp
::
UnboundedRegExpEmpty
<
alphabet
::
Symbol
>
&
)
{
return
false
;
}
// ----------------------------------------------------------------------------
bool
RegExpEpsilon
::
Formal
::
visit
(
const
regexp
::
FormalRegExpAlternation
<
alphabet
::
Symbol
>
&
alternation
)
{
return
alternation
.
getLeftElement
().
accept
<
bool
,
RegExpEpsilon
::
Formal
>
()
||
alternation
.
getRightElement
().
accept
<
bool
,
RegExpEpsilon
::
Formal
>
();
}
bool
RegExpEpsilon
::
Formal
::
visit
(
const
regexp
::
FormalRegExpConcatenation
<
alphabet
::
Symbol
>
&
concatenation
)
{
return
concatenation
.
getLeftElement
().
accept
<
bool
,
RegExpEpsilon
::
Formal
>
()
&&
concatenation
.
getRightElement
().
accept
<
bool
,
RegExpEpsilon
::
Formal
>
();
}
bool
RegExpEpsilon
::
Formal
::
visit
(
const
regexp
::
FormalRegExpIteration
<
alphabet
::
Symbol
>
&
)
{
return
true
;
}
bool
RegExpEpsilon
::
Formal
::
visit
(
const
regexp
::
FormalRegExpSymbol
<
alphabet
::
Symbol
>
&
)
{
return
false
;
}
bool
RegExpEpsilon
::
Formal
::
visit
(
const
regexp
::
FormalRegExpEmpty
<
alphabet
::
Symbol
>
&
)
{
return
false
;
}
bool
RegExpEpsilon
::
Formal
::
visit
(
const
regexp
::
FormalRegExpEpsilon
<
alphabet
::
Symbol
>
&
)
{
return
true
;
}
}
/* namespace properties */
}
/* namespace properties */
}
/* namespace regexp */
}
/* namespace regexp */
This diff is collapsed.
Click to expand it.
alib2algo/src/regexp/properties/RegExpEpsilon.h
+
132
−
18
View file @
c3860b98
...
@@ -28,35 +28,149 @@ class RegExpEpsilon : public std::SingleDispatch<RegExpEpsilon, bool, const rege
...
@@ -28,35 +28,149 @@ class RegExpEpsilon : public std::SingleDispatch<RegExpEpsilon, bool, const rege
public:
public:
static bool languageContainsEpsilon(const regexp::RegExp& regexp);
static bool languageContainsEpsilon(const regexp::RegExp& regexp);
static bool languageContainsEpsilon(const regexp::FormalRegExpElement < alphabet::Symbol > & regexp);
template < class SymbolType >
static bool languageContainsEpsilon(const regexp::FormalRegExpStructure < alphabet::Symbol > & regexp);
static bool languageContainsEpsilon(const regexp::FormalRegExpElement < SymbolType > & regexp);
static bool languageContainsEpsilon(const regexp::FormalRegExp < > & regexp);
template < class SymbolType >
static bool languageContainsEpsilon(const regexp::FormalRegExpStructure < SymbolType > & regexp);
template < class SymbolType >
static bool languageContainsEpsilon(const regexp::FormalRegExp < SymbolType > & regexp);
static bool languageContainsEpsilon(const regexp::UnboundedRegExpElement < alphabet::Symbol > & regexp);
template < class SymbolType >
static bool languageContainsEpsilon(const regexp::UnboundedRegExpStructure < alphabet::Symbol > & regexp);
static bool languageContainsEpsilon(const regexp::UnboundedRegExpElement < SymbolType > & regexp);
static bool languageContainsEpsilon(const regexp::UnboundedRegExp < > & regexp);
template < class SymbolType >
static bool languageContainsEpsilon(const regexp::UnboundedRegExpStructure < SymbolType > & regexp);
template < class SymbolType >
static bool languageContainsEpsilon(const regexp::UnboundedRegExp < SymbolType > & regexp);
template < class SymbolType >
class Unbounded {
class Unbounded {
public:
public:
static bool visit(const regexp::UnboundedRegExpAlternation <
alphabet::
Symbol > & alternation);
static bool visit(const regexp::UnboundedRegExpAlternation < Symbol
Type
> & alternation);
static bool visit(const regexp::UnboundedRegExpConcatenation <
alphabet::
Symbol > & concatenation);
static bool visit(const regexp::UnboundedRegExpConcatenation < Symbol
Type
> & concatenation);
static bool visit(const regexp::UnboundedRegExpIteration <
alphabet::
Symbol > & iteration);
static bool visit(const regexp::UnboundedRegExpIteration < Symbol
Type
> & iteration);
static bool visit(const regexp::UnboundedRegExpSymbol <
alphabet::
Symbol > & symbol);
static bool visit(const regexp::UnboundedRegExpSymbol < Symbol
Type
> & symbol);
static bool visit(const regexp::UnboundedRegExpEmpty <
alphabet::
Symbol > & empty);
static bool visit(const regexp::UnboundedRegExpEmpty < Symbol
Type
> & empty);
static bool visit(const regexp::UnboundedRegExpEpsilon <
alphabet::
Symbol > & epsilon);
static bool visit(const regexp::UnboundedRegExpEpsilon < Symbol
Type
> & epsilon);
};
};
template < class SymbolType >
class Formal {
class Formal {
public:
public:
static bool visit(const regexp::FormalRegExpAlternation <
alphabet::
Symbol > & alternation);
static bool visit(const regexp::FormalRegExpAlternation < Symbol
Type
> & alternation);
static bool visit(const regexp::FormalRegExpConcatenation <
alphabet::
Symbol > & concatenation);
static bool visit(const regexp::FormalRegExpConcatenation < Symbol
Type
> & concatenation);
static bool visit(const regexp::FormalRegExpIteration <
alphabet::
Symbol > & iteration);
static bool visit(const regexp::FormalRegExpIteration < Symbol
Type
> & iteration);
static bool visit(const regexp::FormalRegExpSymbol <
alphabet::
Symbol > & symbol);
static bool visit(const regexp::FormalRegExpSymbol < Symbol
Type
> & symbol);
static bool visit(const regexp::FormalRegExpEmpty <
alphabet::
Symbol > & empty);
static bool visit(const regexp::FormalRegExpEmpty < Symbol
Type
> & empty);
static bool visit(const regexp::FormalRegExpEpsilon <
alphabet::
Symbol > & epsilon);
static bool visit(const regexp::FormalRegExpEpsilon < Symbol
Type
> & epsilon);
};
};
};
};
// ----------------------------------------------------------------------------
template < class SymbolType >
bool RegExpEpsilon::languageContainsEpsilon(const regexp::FormalRegExpElement < SymbolType > & regexp) {
return regexp.template accept<bool, RegExpEpsilon::Formal < SymbolType >>();
}
template < class SymbolType >
bool RegExpEpsilon::languageContainsEpsilon(const regexp::FormalRegExpStructure < SymbolType > & regexp) {
return languageContainsEpsilon(regexp.getStructure());
}
template < class SymbolType >
bool RegExpEpsilon::languageContainsEpsilon(const regexp::FormalRegExp < SymbolType > & regexp) {
return languageContainsEpsilon(regexp.getRegExp());
}
// ----------------------------------------------------------------------------
template < class SymbolType >
bool RegExpEpsilon::languageContainsEpsilon(const regexp::UnboundedRegExpElement < SymbolType > & regexp) {
return regexp.template accept<bool, RegExpEpsilon::Unbounded < SymbolType >>();
}
template < class SymbolType >
bool RegExpEpsilon::languageContainsEpsilon(const regexp::UnboundedRegExpStructure < SymbolType > & regexp) {
return languageContainsEpsilon(regexp.getStructure());
}
template < class SymbolType >
bool RegExpEpsilon::languageContainsEpsilon(const regexp::UnboundedRegExp < SymbolType > & regexp) {
return languageContainsEpsilon(regexp.getRegExp());
}
// ---------------------------------------------------------------------------
template < class SymbolType >
bool RegExpEpsilon::Unbounded < SymbolType >::visit(const regexp::UnboundedRegExpAlternation < SymbolType > & alternation) {
for ( const auto & element : alternation.getElements ( ) )
if ( element->template accept < bool, RegExpEpsilon::Unbounded < SymbolType > > ( ) )
return true;
return false;
}
template < class SymbolType >
bool RegExpEpsilon::Unbounded < SymbolType >::visit(const regexp::UnboundedRegExpConcatenation < SymbolType > & concatenation) {
for ( const auto & element : concatenation.getElements ( ) )
if ( ! element->template accept < bool, RegExpEpsilon::Unbounded < SymbolType > > ( ) )
return false;
return true;
}
template < class SymbolType >
bool RegExpEpsilon::Unbounded < SymbolType >::visit(const regexp::UnboundedRegExpIteration < SymbolType > &) {
return true;
}
template < class SymbolType >
bool RegExpEpsilon::Unbounded < SymbolType >::visit(const regexp::UnboundedRegExpSymbol < SymbolType > &) {
return false;
}
template < class SymbolType >
bool RegExpEpsilon::Unbounded < SymbolType >::visit(const regexp::UnboundedRegExpEpsilon < SymbolType > &) {
return true;
}
template < class SymbolType >
bool RegExpEpsilon::Unbounded < SymbolType >::visit(const regexp::UnboundedRegExpEmpty < SymbolType > &) {
return false;
}
// ----------------------------------------------------------------------------
template < class SymbolType >
bool RegExpEpsilon::Formal < SymbolType >::visit(const regexp::FormalRegExpAlternation < SymbolType > & alternation) {
return alternation.getLeftElement().template accept<bool, RegExpEpsilon::Formal < SymbolType >>() || alternation.getRightElement().template accept<bool, RegExpEpsilon::Formal < SymbolType >>();
}
template < class SymbolType >
bool RegExpEpsilon::Formal < SymbolType >::visit(const regexp::FormalRegExpConcatenation < SymbolType > & concatenation) {
return concatenation.getLeftElement().template accept<bool, RegExpEpsilon::Formal < SymbolType >>() && concatenation.getRightElement().template accept<bool, RegExpEpsilon::Formal < SymbolType >>();
}
template < class SymbolType >
bool RegExpEpsilon::Formal < SymbolType >::visit(const regexp::FormalRegExpIteration < SymbolType > &) {
return true;
}
template < class SymbolType >
bool RegExpEpsilon::Formal < SymbolType >::visit(const regexp::FormalRegExpSymbol < SymbolType > &) {
return false;
}
template < class SymbolType >
bool RegExpEpsilon::Formal < SymbolType >::visit(const regexp::FormalRegExpEmpty < SymbolType > &) {
return false;
}
template < class SymbolType >
bool RegExpEpsilon::Formal < SymbolType >::visit(const regexp::FormalRegExpEpsilon < SymbolType > &) {
return true;
}
} /* namespace properties */
} /* namespace properties */
} /* namespace regexp */
} /* namespace regexp */
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment