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
869be8b9
Commit
869be8b9
authored
3 years ago
by
Jan Trávníček
Browse files
Options
Downloads
Patches
Plain Diff
data: simplify grammar rules unification
parent
32e97a23
No related branches found
No related tags found
1 merge request
!204
Merge jt
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
alib2data/src/grammar/AddRawRule.h
+14
-7
14 additions, 7 deletions
alib2data/src/grammar/AddRawRule.h
alib2data/src/grammar/RawRules.h
+12
-20
12 additions, 20 deletions
alib2data/src/grammar/RawRules.h
with
26 additions
and
27 deletions
alib2data/src/grammar/AddRawRule.h
+
14
−
7
View file @
869be8b9
...
@@ -101,10 +101,12 @@ bool AddRawRule::addRawRule ( LG < TerminalSymbolType, NonterminalSymbolType > &
...
@@ -101,10 +101,12 @@ bool AddRawRule::addRawRule ( LG < TerminalSymbolType, NonterminalSymbolType > &
ext::vector < TerminalSymbolType > rhs1;
ext::vector < TerminalSymbolType > rhs1;
ext::vector < TerminalSymbolType > rhs2;
ext::vector < TerminalSymbolType > rhs2;
for
( ext::variant < TerminalSymbolType, NonterminalSymbolType > & symbol
: ext::make_iterator_range ( rightHandSide.begin ( ), nonterminalPosition ) )
std::for_each ( rightHandSide.begin ( ), nonterminalPosition, [ & ]
( ext::variant < TerminalSymbolType, NonterminalSymbolType > & symbol
) {
rhs1.push_back ( std::move ( symbol.template get < TerminalSymbolType > ( ) ) );
rhs1.push_back ( std::move ( symbol.template get < TerminalSymbolType > ( ) ) );
for ( ext::variant < TerminalSymbolType, NonterminalSymbolType > & symbol : ext::make_iterator_range ( std::next ( nonterminalPosition ), rightHandSide.end ( ) ) )
} );
std::for_each ( std::next ( nonterminalPosition ), rightHandSide.end ( ), [ & ] ( ext::variant < TerminalSymbolType, NonterminalSymbolType > & symbol ) {
rhs2.push_back ( std::move ( symbol.template get < TerminalSymbolType > ( ) ) );
rhs2.push_back ( std::move ( symbol.template get < TerminalSymbolType > ( ) ) );
} );
return grammar.addRule ( leftHandSide, ext::make_tuple ( std::move ( rhs1 ), std::move ( nonterminalPosition->template get < NonterminalSymbolType > ( ) ), std::move ( rhs2 ) ) );
return grammar.addRule ( leftHandSide, ext::make_tuple ( std::move ( rhs1 ), std::move ( nonterminalPosition->template get < NonterminalSymbolType > ( ) ), std::move ( rhs2 ) ) );
}
}
...
@@ -123,8 +125,9 @@ bool AddRawRule::addRawRule ( GNF < TerminalSymbolType, NonterminalSymbolType >
...
@@ -123,8 +125,9 @@ bool AddRawRule::addRawRule ( GNF < TerminalSymbolType, NonterminalSymbolType >
TerminalSymbolType first = std::move ( rightHandSide[0].template get < TerminalSymbolType > ( ) );
TerminalSymbolType first = std::move ( rightHandSide[0].template get < TerminalSymbolType > ( ) );
ext::vector < NonterminalSymbolType > rest;
ext::vector < NonterminalSymbolType > rest;
for ( ext::variant < TerminalSymbolType, NonterminalSymbolType > & element : ext::make_iterator_range ( rightHandSide.begin ( ) + 1, rightHandSide.end ( ) ) )
std::for_each ( rightHandSide.begin ( ) + 1, rightHandSide.end ( ), [ & ] ( ext::variant < TerminalSymbolType, NonterminalSymbolType > & element ) {
rest.push_back ( std::move ( element.template get < NonterminalSymbolType > ( ) ) );
rest.push_back ( std::move ( element.template get < NonterminalSymbolType > ( ) ) );
} );
return grammar.addRule ( std::move ( leftHandSide ), ext::make_pair ( std::move ( first ), std::move ( rest ) ) );
return grammar.addRule ( std::move ( leftHandSide ), ext::make_pair ( std::move ( first ), std::move ( rest ) ) );
}
}
...
@@ -173,14 +176,16 @@ bool AddRawRule::addRawRule ( LeftLG < TerminalSymbolType, NonterminalSymbolType
...
@@ -173,14 +176,16 @@ bool AddRawRule::addRawRule ( LeftLG < TerminalSymbolType, NonterminalSymbolType
return grammar.addRule ( std::move ( leftHandSide ), ext::vector < TerminalSymbolType > { } );
return grammar.addRule ( std::move ( leftHandSide ), ext::vector < TerminalSymbolType > { } );
else if ( grammar.getNonterminalAlphabet ( ).count ( rightHandSide [ 0 ] ) ) {
else if ( grammar.getNonterminalAlphabet ( ).count ( rightHandSide [ 0 ] ) ) {
ext::vector < TerminalSymbolType > rhs;
ext::vector < TerminalSymbolType > rhs;
for ( ext::variant < TerminalSymbolType, NonterminalSymbolType > & element : ext::make_iterator_range ( rightHandSide.begin ( ) + 1, rightHandSide.end ( ) ) )
std::for_each ( rightHandSide.begin ( ) + 1, rightHandSide.end ( ), [ & ] ( ext::variant < TerminalSymbolType, NonterminalSymbolType > & element ) {
rhs.push_back ( std::move ( element.template get < TerminalSymbolType > ( ) ) );
rhs.push_back ( std::move ( element.template get < TerminalSymbolType > ( ) ) );
} );
return grammar.addRule ( std::move ( leftHandSide ), ext::make_pair ( std::move ( rightHandSide [ 0 ].template get < NonterminalSymbolType > ( ) ), std::move ( rhs ) ) );
return grammar.addRule ( std::move ( leftHandSide ), ext::make_pair ( std::move ( rightHandSide [ 0 ].template get < NonterminalSymbolType > ( ) ), std::move ( rhs ) ) );
} else {
} else {
ext::vector < TerminalSymbolType > rhs;
ext::vector < TerminalSymbolType > rhs;
for
( ext::variant < TerminalSymbolType, NonterminalSymbolType > & element
: ext::make_iterator_range ( rightHandSide.begin ( ), rightHandSide.end ( ) ) )
std::for_each ( rightHandSide.begin ( ), rightHandSide.end ( ), [ & ]
( ext::variant < TerminalSymbolType, NonterminalSymbolType > & element
) {
rhs.push_back ( std::move ( element.template get < TerminalSymbolType > ( ) ) );
rhs.push_back ( std::move ( element.template get < TerminalSymbolType > ( ) ) );
} );
return grammar.addRule ( std::move ( leftHandSide ), std::move ( rhs ) );
return grammar.addRule ( std::move ( leftHandSide ), std::move ( rhs ) );
}
}
...
@@ -228,14 +233,16 @@ bool AddRawRule::addRawRule ( RightLG < TerminalSymbolType, NonterminalSymbolTyp
...
@@ -228,14 +233,16 @@ bool AddRawRule::addRawRule ( RightLG < TerminalSymbolType, NonterminalSymbolTyp
return grammar.addRule ( std::move ( leftHandSide ), ext::vector < TerminalSymbolType > { } );
return grammar.addRule ( std::move ( leftHandSide ), ext::vector < TerminalSymbolType > { } );
else if ( grammar.getNonterminalAlphabet ( ).count ( rightHandSide [ rightHandSide.size ( ) - 1 ] ) ) {
else if ( grammar.getNonterminalAlphabet ( ).count ( rightHandSide [ rightHandSide.size ( ) - 1 ] ) ) {
ext::vector < TerminalSymbolType > rhs;
ext::vector < TerminalSymbolType > rhs;
for ( ext::variant < TerminalSymbolType, NonterminalSymbolType > & element : ext::make_iterator_range ( rightHandSide.begin ( ), rightHandSide.end ( ) - 1 ) )
std::for_each ( rightHandSide.begin ( ), rightHandSide.end ( ) - 1, [ & ] ( ext::variant < TerminalSymbolType, NonterminalSymbolType > & element ) {
rhs.push_back ( std::move ( element.template get < TerminalSymbolType > ( ) ) );
rhs.push_back ( std::move ( element.template get < TerminalSymbolType > ( ) ) );
} );
return grammar.addRule ( std::move ( leftHandSide ), ext::make_pair ( std::move ( rhs ), std::move ( rightHandSide [ rightHandSide.size ( ) - 1 ].template get < NonterminalSymbolType > ( ) ) ) );
return grammar.addRule ( std::move ( leftHandSide ), ext::make_pair ( std::move ( rhs ), std::move ( rightHandSide [ rightHandSide.size ( ) - 1 ].template get < NonterminalSymbolType > ( ) ) ) );
} else {
} else {
ext::vector < TerminalSymbolType > rhs;
ext::vector < TerminalSymbolType > rhs;
for
( ext::variant < TerminalSymbolType, NonterminalSymbolType > & element
: ext::make_iterator_range ( rightHandSide.begin ( ), rightHandSide.end ( ) ) )
std::for_each ( rightHandSide.begin ( ), rightHandSide.end ( ), [ & ]
( ext::variant < TerminalSymbolType, NonterminalSymbolType > & element
) {
rhs.push_back ( std::move ( element.template get < TerminalSymbolType > ( ) ) );
rhs.push_back ( std::move ( element.template get < TerminalSymbolType > ( ) ) );
} );
return grammar.addRule ( std::move ( leftHandSide ), std::move ( rhs ) );
return grammar.addRule ( std::move ( leftHandSide ), std::move ( rhs ) );
}
}
...
...
This diff is collapsed.
Click to expand it.
alib2data/src/grammar/RawRules.h
+
12
−
20
View file @
869be8b9
...
@@ -92,18 +92,15 @@ ext::map < NonterminalSymbolType, ext::set < ext::vector < ext::variant < Termin
...
@@ -92,18 +92,15 @@ ext::map < NonterminalSymbolType, ext::set < ext::vector < ext::variant < Termin
ext::vector < ext::variant < TerminalSymbolType, NonterminalSymbolType > > tmp;
ext::vector < ext::variant < TerminalSymbolType, NonterminalSymbolType > > tmp;
if ( rhs.template is < ext::vector < TerminalSymbolType > > ( ) ) {
if ( rhs.template is < ext::vector < TerminalSymbolType > > ( ) ) {
for ( const TerminalSymbolType & symbol : rhs.template get < ext::vector < TerminalSymbolType > > ( ) )
tmp.insert ( tmp.end ( ), rhs.template get < ext::vector < TerminalSymbolType > > ( ).begin ( ), rhs.template get < ext::vector < TerminalSymbolType > > ( ).end ( ) );
tmp.push_back ( ext::variant < TerminalSymbolType, NonterminalSymbolType > ( symbol ) );
} else {
} else {
const auto & rhsTuple = rhs.template get < ext::tuple < ext::vector < TerminalSymbolType >, NonterminalSymbolType, ext::vector < TerminalSymbolType > > > ( );
const auto & rhsTuple = rhs.template get < ext::tuple < ext::vector < TerminalSymbolType >, NonterminalSymbolType, ext::vector < TerminalSymbolType > > > ( );
for ( const TerminalSymbolType & symbol : ext::make_iterator_range ( std::get < 0 > ( rhsTuple ).begin ( ), std::get < 0 > ( rhsTuple ).end ( ) ) )
tmp.insert ( tmp.end ( ), std::get < 0 > ( rhsTuple ).begin ( ), std::get < 0 > ( rhsTuple ).end ( ) );
tmp.push_back ( ext::variant < TerminalSymbolType, NonterminalSymbolType > ( symbol ) );
tmp.push_back (
ext::variant < TerminalSymbolType, NonterminalSymbolType > (
std::get < 1 > ( rhsTuple )
)
);
tmp.push_back ( std::get < 1 > ( rhsTuple ) );
for ( const TerminalSymbolType & symbol : ext::make_iterator_range ( std::get < 2 > ( rhsTuple ).begin ( ), std::get < 2 > ( rhsTuple ).end ( ) ) )
tmp.insert ( tmp.end ( ), std::get < 2 > ( rhsTuple ).begin ( ), std::get < 2 > ( rhsTuple ).end ( ) );
tmp.push_back ( ext::variant < TerminalSymbolType, NonterminalSymbolType > ( symbol ) );
}
}
res[rule.first].insert ( std::move ( tmp ) );
res[rule.first].insert ( std::move ( tmp ) );
...
@@ -119,10 +116,9 @@ ext::map < NonterminalSymbolType, ext::set < ext::vector < ext::variant < Termin
...
@@ -119,10 +116,9 @@ ext::map < NonterminalSymbolType, ext::set < ext::vector < ext::variant < Termin
for ( const auto & rule : grammar.getRules ( ) )
for ( const auto & rule : grammar.getRules ( ) )
for ( const auto & rhs : rule.second ) {
for ( const auto & rhs : rule.second ) {
ext::vector < ext::variant < TerminalSymbolType, NonterminalSymbolType > > tmp;
ext::vector < ext::variant < TerminalSymbolType, NonterminalSymbolType > > tmp;
tmp.push_back (
ext::variant < TerminalSymbolType, NonterminalSymbolType > (
rhs.first
)
);
tmp.push_back ( rhs.first );
for ( const NonterminalSymbolType & symbol : ext::make_iterator_range ( rhs.second.begin ( ), rhs.second.end ( ) ) )
tmp.insert ( tmp.end ( ), rhs.second.begin ( ), rhs.second.end ( ) );
tmp.push_back ( ext::variant < TerminalSymbolType, NonterminalSymbolType > ( symbol ) );
res[rule.first].insert ( std::move ( tmp ) );
res[rule.first].insert ( std::move ( tmp ) );
}
}
...
@@ -179,14 +175,12 @@ ext::map < NonterminalSymbolType, ext::set < ext::vector < ext::variant < Termin
...
@@ -179,14 +175,12 @@ ext::map < NonterminalSymbolType, ext::set < ext::vector < ext::variant < Termin
ext::vector < ext::variant < TerminalSymbolType, NonterminalSymbolType > > tmp;
ext::vector < ext::variant < TerminalSymbolType, NonterminalSymbolType > > tmp;
if ( rhs.template is < ext::vector < TerminalSymbolType > > ( ) ) {
if ( rhs.template is < ext::vector < TerminalSymbolType > > ( ) ) {
for ( const TerminalSymbolType & symbol : rhs.template get < ext::vector < TerminalSymbolType > > ( ) )
tmp.insert ( tmp.end ( ), rhs.template get < ext::vector < TerminalSymbolType > > ( ).begin ( ), rhs.template get < ext::vector < TerminalSymbolType > > ( ).end ( ) );
tmp.push_back ( ext::variant < TerminalSymbolType, NonterminalSymbolType > ( symbol ) );
} else {
} else {
const auto & rhsTuple = rhs.template get < ext::pair < NonterminalSymbolType, ext::vector < TerminalSymbolType > > > ( );
const auto & rhsTuple = rhs.template get < ext::pair < NonterminalSymbolType, ext::vector < TerminalSymbolType > > > ( );
tmp.push_back ( ext::variant < TerminalSymbolType, NonterminalSymbolType > ( rhsTuple.first ) );
tmp.push_back ( rhsTuple.first );
for ( const TerminalSymbolType & symbol : ext::make_iterator_range ( rhsTuple.second.begin ( ), rhsTuple.second.end ( ) ) )
tmp.insert ( tmp.end ( ), rhsTuple.second.begin ( ), rhsTuple.second.end ( ) );
tmp.push_back ( ext::variant < TerminalSymbolType, NonterminalSymbolType > ( symbol ) );
}
}
res[rule.first].insert ( std::move ( tmp ) );
res[rule.first].insert ( std::move ( tmp ) );
...
@@ -248,14 +242,12 @@ ext::map < NonterminalSymbolType, ext::set < ext::vector < ext::variant < Termin
...
@@ -248,14 +242,12 @@ ext::map < NonterminalSymbolType, ext::set < ext::vector < ext::variant < Termin
ext::vector < ext::variant < TerminalSymbolType, NonterminalSymbolType > > tmp;
ext::vector < ext::variant < TerminalSymbolType, NonterminalSymbolType > > tmp;
if ( rhs.template is < ext::vector < TerminalSymbolType > > ( ) ) {
if ( rhs.template is < ext::vector < TerminalSymbolType > > ( ) ) {
for ( const TerminalSymbolType & symbol : rhs.template get < ext::vector < TerminalSymbolType > > ( ) )
tmp.insert ( tmp.end ( ), rhs.template get < ext::vector < TerminalSymbolType > > ( ).begin ( ), rhs.template get < ext::vector < TerminalSymbolType > > ( ).end ( ) );
tmp.push_back ( ext::variant < TerminalSymbolType, NonterminalSymbolType > ( symbol ) );
} else {
} else {
const auto & rhsTuple = rhs.template get < ext::pair < ext::vector < TerminalSymbolType >, NonterminalSymbolType > > ( );
const auto & rhsTuple = rhs.template get < ext::pair < ext::vector < TerminalSymbolType >, NonterminalSymbolType > > ( );
for ( const TerminalSymbolType & symbol : ext::make_iterator_range ( rhsTuple.first.begin ( ), rhsTuple.first.end ( ) ) )
tmp.insert ( tmp.end ( ), rhsTuple.first.begin ( ), rhsTuple.first.end ( ) );
tmp.push_back ( ext::variant < TerminalSymbolType, NonterminalSymbolType > ( symbol ) );
tmp.push_back ( rhsTuple.second );
tmp.push_back ( ext::variant < TerminalSymbolType, NonterminalSymbolType > ( rhsTuple.second ) );
}
}
res[rule.first].insert ( std::move ( tmp ) );
res[rule.first].insert ( std::move ( tmp ) );
...
...
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