Toggle navigation
Toggle navigation
This project
Loading...
Sign in
Franck Pommereau
/
zinc
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Authored by
Franck Pommereau
2017-12-04 10:08:05 +0100
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
21516c042e1ef0ef7fc1fd7878a192109f5553cb
21516c04
1 parent
a2f3c181
fixed bug with consumed+produced tokens
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
31 additions
and
7 deletions
zinc/data.py
zinc/nodes.py
zinc/data.py
View file @
21516c0
...
...
@@ -133,6 +133,10 @@ class mset (Counter) :
True
>>> mset('abcd') - mset('abcd') == mset('')
True
>>> mset('abc') - mset('abcd')
Traceback (most recent call last):
...
ValueError: not enough occurrences
"""
new
=
self
.
__class__
()
for
key
in
set
(
self
)
|
set
(
other
)
:
...
...
@@ -142,6 +146,23 @@ class mset (Counter) :
elif
count
<
0
:
raise
ValueError
(
"not enough occurrences"
)
return
new
def
__truediv__
(
self
,
other
)
:
"""
>>> mset('abcd') / mset('ab') == mset('cd')
True
>>> mset('aabbcd') / mset('ab') == mset('abcd')
True
>>> mset('abcd') / mset('abcd') == mset('')
True
>>> mset('abc') / mset('abcdef') == mset('')
True
"""
new
=
self
.
__class__
()
for
key
in
set
(
self
)
|
set
(
other
)
:
count
=
self
(
key
)
-
other
(
key
)
if
count
>
0
:
new
[
key
]
=
count
return
new
def
__add__
(
self
,
other
)
:
"""
>>> mset('abcd') + mset('ab') == mset('ab' + 'abcd')
...
...
zinc/nodes.py
View file @
21516c0
...
...
@@ -97,28 +97,31 @@ class Transition (Node) :
# eliminate tokens that are both consumed & produced in the same place
for
place
in
set
(
ctx
.
sub
)
&
set
(
ctx
.
add
)
:
sub
=
mset
(
ctx
.
sub
[
place
])
sub
.
discard
(
ctx
.
add
[
place
])
add
=
mset
(
ctx
.
add
[
place
])
add
.
discard
(
ctx
.
sub
[
place
])
if
sub
:
ctx
.
sub
[
place
]
=
list
(
sub
)
newsub
=
sub
/
add
newadd
=
add
/
sub
if
newsub
!=
sub
:
ctx
.
test
[
place
]
.
extend
(
sub
&
add
)
if
newsub
:
ctx
.
sub
[
place
]
=
list
(
newsub
)
else
:
del
ctx
.
sub
[
place
]
if
add
:
if
new
add
:
ctx
.
add
[
place
]
=
list
(
add
)
else
:
del
ctx
.
add
[
place
]
# eliminate empty places
for
mk
in
(
ctx
.
sub
,
ctx
.
add
)
:
for
mk
in
(
ctx
.
sub
,
ctx
.
add
,
ctx
.
test
)
:
for
place
,
tokens
in
list
(
mk
.
items
())
:
if
not
tokens
:
del
mk
[
place
]
#
code to produce successor marking
#
also test for tokens that will be consumed
if
ctx
.
test
:
for
place
,
tokens
in
ctx
.
sub
.
items
()
:
ctx
.
test
[
place
]
.
extend
(
tokens
)
else
:
ctx
.
test
=
{}
# code to produce successor marking
tip
=
ctx
.
IfEnoughTokens
(
ctx
.
marking
,
ctx
.
test
,
ctx
.
sub
,
ctx
.
add
,
BLAME
=
ctx
.
TransitionBlame
(
self
.
name
))
last
.
append
(
tip
)
...
...
Please
register
or
login
to post a comment