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
21927677
Commit
21927677
authored
10 years ago
by
Jan Trávníček
Browse files
Options
Downloads
Patches
Plain Diff
NullableNonterminals visitor
parent
ea085782
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/grammar/properties/NullableNonterminals.cpp
+72
-1
72 additions, 1 deletion
alib2algo/src/grammar/properties/NullableNonterminals.cpp
alib2algo/src/grammar/properties/NullableNonterminals.h
+21
-7
21 additions, 7 deletions
alib2algo/src/grammar/properties/NullableNonterminals.h
with
93 additions
and
8 deletions
alib2algo/src/grammar/properties/NullableNonterminals.cpp
+
72
−
1
View file @
21927677
...
...
@@ -17,7 +17,9 @@
#include
<grammar/Regular/RightLG.h>
#include
<grammar/Regular/RightRG.h>
#include
<std/set.hpp>
#include
<set>
#include
<deque>
#include
<algorithm>
namespace
grammar
{
...
...
@@ -59,6 +61,75 @@ template std::set<alphabet::Symbol> NullableNonterminals::getNullableNonterminal
template
std
::
set
<
alphabet
::
Symbol
>
NullableNonterminals
::
getNullableNonterminals
(
const
grammar
::
RightLG
&
grammar
);
template
std
::
set
<
alphabet
::
Symbol
>
NullableNonterminals
::
getNullableNonterminals
(
const
grammar
::
RightRG
&
grammar
);
std
::
set
<
alphabet
::
Symbol
>
NullableNonterminals
::
getNullableNonterminals
(
const
grammar
::
Grammar
&
grammar
)
{
std
::
set
<
alphabet
::
Symbol
>
out
;
grammar
.
getData
().
Accept
((
void
*
)
&
out
,
NullableNonterminals
::
NULLABLE_NONTERMINALS
);
return
out
;
}
void
NullableNonterminals
::
Visit
(
void
*
data
,
const
grammar
::
LeftLG
&
grammar
)
const
{
std
::
set
<
alphabet
::
Symbol
>
&
out
=
*
((
std
::
set
<
alphabet
::
Symbol
>*
)
data
);
out
=
std
::
move
(
this
->
getNullableNonterminals
(
grammar
));
}
void
NullableNonterminals
::
Visit
(
void
*
data
,
const
grammar
::
LeftRG
&
grammar
)
const
{
std
::
set
<
alphabet
::
Symbol
>
&
out
=
*
((
std
::
set
<
alphabet
::
Symbol
>*
)
data
);
out
=
std
::
move
(
this
->
getNullableNonterminals
(
grammar
));
}
void
NullableNonterminals
::
Visit
(
void
*
data
,
const
grammar
::
RightLG
&
grammar
)
const
{
std
::
set
<
alphabet
::
Symbol
>
&
out
=
*
((
std
::
set
<
alphabet
::
Symbol
>*
)
data
);
out
=
std
::
move
(
this
->
getNullableNonterminals
(
grammar
));
}
void
NullableNonterminals
::
Visit
(
void
*
data
,
const
grammar
::
RightRG
&
grammar
)
const
{
std
::
set
<
alphabet
::
Symbol
>
&
out
=
*
((
std
::
set
<
alphabet
::
Symbol
>*
)
data
);
out
=
std
::
move
(
this
->
getNullableNonterminals
(
grammar
));
}
void
NullableNonterminals
::
Visit
(
void
*
data
,
const
grammar
::
LG
&
grammar
)
const
{
std
::
set
<
alphabet
::
Symbol
>
&
out
=
*
((
std
::
set
<
alphabet
::
Symbol
>*
)
data
);
out
=
std
::
move
(
this
->
getNullableNonterminals
(
grammar
));
}
void
NullableNonterminals
::
Visit
(
void
*
data
,
const
grammar
::
CFG
&
grammar
)
const
{
std
::
set
<
alphabet
::
Symbol
>
&
out
=
*
((
std
::
set
<
alphabet
::
Symbol
>*
)
data
);
out
=
std
::
move
(
this
->
getNullableNonterminals
(
grammar
));
}
void
NullableNonterminals
::
Visit
(
void
*
data
,
const
grammar
::
EpsilonFreeCFG
&
grammar
)
const
{
std
::
set
<
alphabet
::
Symbol
>
&
out
=
*
((
std
::
set
<
alphabet
::
Symbol
>*
)
data
);
out
=
std
::
move
(
this
->
getNullableNonterminals
(
grammar
));
}
void
NullableNonterminals
::
Visit
(
void
*
data
,
const
grammar
::
CNF
&
grammar
)
const
{
std
::
set
<
alphabet
::
Symbol
>
&
out
=
*
((
std
::
set
<
alphabet
::
Symbol
>*
)
data
);
out
=
std
::
move
(
this
->
getNullableNonterminals
(
grammar
));
}
void
NullableNonterminals
::
Visit
(
void
*
data
,
const
grammar
::
GNF
&
grammar
)
const
{
std
::
set
<
alphabet
::
Symbol
>
&
out
=
*
((
std
::
set
<
alphabet
::
Symbol
>*
)
data
);
out
=
std
::
move
(
this
->
getNullableNonterminals
(
grammar
));
}
void
NullableNonterminals
::
Visit
(
void
*
,
const
grammar
::
CSG
&
)
const
{
throw
exception
::
AlibException
(
"Unsupported grammar type CSG"
);
}
void
NullableNonterminals
::
Visit
(
void
*
,
const
grammar
::
NonContractingGrammar
&
)
const
{
throw
exception
::
AlibException
(
"Unsupported grammar type NonConctractingGrammar"
);
}
void
NullableNonterminals
::
Visit
(
void
*
,
const
grammar
::
ContextPreservingUnrestrictedGrammar
&
)
const
{
throw
exception
::
AlibException
(
"Unsupported grammar type ContextPreservingUnrestrictedGrammar"
);
}
void
NullableNonterminals
::
Visit
(
void
*
,
const
grammar
::
UnrestrictedGrammar
&
)
const
{
throw
exception
::
AlibException
(
"Unsupported grammar type UnrestrictedGrammar"
);
}
const
NullableNonterminals
NullableNonterminals
::
NULLABLE_NONTERMINALS
;
}
/* namespace properties */
}
/* namespace grammar */
This diff is collapsed.
Click to expand it.
alib2algo/src/grammar/properties/NullableNonterminals.h
+
21
−
7
View file @
21927677
...
...
@@ -8,12 +8,7 @@
#ifndef NULLABLE_NONTERMINALS_H_
#define NULLABLE_NONTERMINALS_H_
#include <algorithm>
#include <deque>
#include <set>
#include <exception/AlibException.h>
#include <grammar/Grammar.h>
#include <alphabet/Symbol.h>
namespace grammar {
...
...
@@ -23,8 +18,10 @@ namespace properties {
/**
* Implements algorithms from Melichar, chapter 3.3
*/
class NullableNonterminals {
class NullableNonterminals
: public grammar::VisitableGrammarBase::const_visitor_type
{
public:
static std::set<alphabet::Symbol> getNullableNonterminals( const grammar::Grammar & grammar );
/**
* Retrieve all nullable nonterminals from grammar
* Nullable nonterminal is such nonterminal A for which holds that A ->^* \eps
...
...
@@ -36,6 +33,23 @@ public:
*/
template<class T>
static std::set<alphabet::Symbol> getNullableNonterminals(const T& grammar);
private:
void Visit(void*, const grammar::LeftLG& grammar) const;
void Visit(void*, const grammar::LeftRG& grammar) const;
void Visit(void*, const grammar::RightLG& grammar) const;
void Visit(void*, const grammar::RightRG& grammar) const;
void Visit(void*, const grammar::LG& grammar) const;
void Visit(void*, const grammar::CFG& grammar) const;
void Visit(void*, const grammar::EpsilonFreeCFG& grammar) const;
void Visit(void*, const grammar::CNF& grammar) const;
void Visit(void*, const grammar::GNF& grammar) const;
void Visit(void*, const grammar::CSG& grammar) const;
void Visit(void*, const grammar::NonContractingGrammar& grammar) const;
void Visit(void*, const grammar::ContextPreservingUnrestrictedGrammar& grammar) const;
void Visit(void*, const grammar::UnrestrictedGrammar& grammar) const;
static const NullableNonterminals NULLABLE_NONTERMINALS;
};
} /* namespace properties */
...
...
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