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
f87d9ef6
Commit
f87d9ef6
authored
10 years ago
by
Tomáš Pecka
Browse files
Options
Downloads
Patches
Plain Diff
atrim: fix and improve grammar trimming
parent
1354c7e9
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
atrim/src/atrim.cpp
+1
-1
1 addition, 1 deletion
atrim/src/atrim.cpp
atrim/src/grammar/ContextFreeGrammarTransformations.cpp
+9
-18
9 additions, 18 deletions
atrim/src/grammar/ContextFreeGrammarTransformations.cpp
tests.aconversion.sh
+1
-1
1 addition, 1 deletion
tests.aconversion.sh
with
11 additions
and
20 deletions
atrim/src/atrim.cpp
+
1
−
1
View file @
f87d9ef6
...
...
@@ -36,7 +36,7 @@ void help( void )
int
main
(
int
argc
,
char
*
argv
[])
{
bool
del_dead_only
=
tru
e
,
del_unreachable_only
=
tru
e
;
bool
del_dead_only
=
fals
e
,
del_unreachable_only
=
fals
e
;
static
struct
option
long_options
[]
=
{
{
"help"
,
no_argument
,
NULL
,
'h'
},
...
...
This diff is collapsed.
Click to expand it.
atrim/src/grammar/ContextFreeGrammarTransformations.cpp
+
9
−
18
View file @
f87d9ef6
...
...
@@ -23,20 +23,12 @@ set<Symbol> ContextFreeGrammarTransformations::getProductiveNonTerminals( const
while
(
true
)
{
Ni
.
push_back
(
Ni
.
at
(
i
-
1
)
);
bool
valid
=
true
;
for
(
const
auto
&
rule
:
grammar
.
getRules
(
)
)
{
for
(
const
auto
&
symbol
:
rule
.
getRightSide
(
)
)
{
if
(
!
isInSet
(
symbol
,
Ni
.
at
(
i
-
1
)
)
&&
!
isInSet
(
symbol
,
grammar
.
getTerminalSymbols
(
)
)
)
{
valid
=
false
;
break
;
}
}
if
(
valid
)
if
(
all_of
(
rule
.
getRightSide
(
).
begin
(
),
rule
.
getRightSide
(
).
end
(
),
[
i
,
Ni
,
grammar
](
Symbol
const
&
symbol
)
->
bool
{
return
isInSet
(
symbol
,
Ni
.
at
(
i
-
1
)
)
||
isInSet
(
symbol
,
grammar
.
getTerminalSymbols
(
)
);
}
)
)
Ni
.
at
(
i
).
insert
(
rule
.
getLeftSide
(
).
front
(
)
);
}
...
...
@@ -57,7 +49,7 @@ bool ContextFreeGrammarTransformations::isLanguageEmpty( const grammar::ContextF
ContextFreeGrammar
ContextFreeGrammarTransformations
::
removeUnreachableSymbols
(
const
ContextFreeGrammar
&
grammar
)
{
// 1
.
// 1
deque
<
set
<
Symbol
>>
Vi
;
Vi
.
push_back
(
set
<
Symbol
>
(
)
);
Vi
.
at
(
0
).
insert
(
grammar
.
getStartSymbol
(
)
);
...
...
@@ -73,10 +65,7 @@ ContextFreeGrammar ContextFreeGrammarTransformations::removeUnreachableSymbols(
{
if
(
isInSet
(
rule
.
getLeftSide
(
).
front
(
),
Vi
.
at
(
i
-
1
)
)
)
{
for
(
const
auto
&
symbol
:
rule
.
getRightSide
(
)
)
{
Vi
.
at
(
i
).
insert
(
symbol
);
}
Vi
.
at
(
i
).
insert
(
rule
.
getRightSide
(
).
begin
(
),
rule
.
getRightSide
(
).
end
(
)
);
}
}
...
...
@@ -103,8 +92,9 @@ ContextFreeGrammar ContextFreeGrammarTransformations::removeUnreachableSymbols(
// A->\alpha: if A \in N' and \alpha in V_i*, then A->\alpha in P
for
(
const
auto
&
rule
:
grammar
.
getRules
(
)
)
{
if
(
isInSet
(
rule
.
getLeftSide
(
).
front
(
)
,
ret
.
getNonTerminalSymbols
(
)
)
&&
all_of
(
rule
.
getRightSide
(
).
begin
(
),
rule
.
getRightSide
(
).
end
(
),
[
Vi
,
i
](
const
Symbol
&
symb
){
return
isInSet
(
symb
,
Vi
.
at
(
i
)
);
}
)
)
if
(
isInSet
(
rule
.
getLeftSide
(
).
front
(
)
,
newNonTerminals
)
&&
all_of
(
rule
.
getRightSide
(
).
begin
(
),
rule
.
getRightSide
(
).
end
(
),
[
Vi
,
i
](
Symbol
const
&
symb
)
->
bool
{
return
isInSet
(
symb
,
Vi
.
at
(
i
)
);
}
)
)
{
ret
.
addRule
(
rule
);
}
...
...
@@ -119,6 +109,7 @@ ContextFreeGrammar ContextFreeGrammarTransformations::removeUnproductiveSymbols(
{
// 1.
set
<
Symbol
>
Nt
=
getProductiveNonTerminals
(
grammar
);
ContextFreeGrammar
G1
;
for
(
const
auto
&
symbol
:
Nt
)
...
...
This diff is collapsed.
Click to expand it.
tests.aconversion.sh
+
1
−
1
View file @
f87d9ef6
#!/usr/bin/env bash
TESTCASE_ITERATIONS
=
20
TESTCASE_ITERATIONS
=
20
0
TESTCASE_TIMEOUT
=
5
LOGFILE
=
"log_tests.txt"
...
...
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