Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
fja
eval
Commits
1ff54cfa
Commit
1ff54cfa
authored
Feb 24, 2020
by
Kateřina Sloupová
Browse files
some typing fixes, no more empty automata
parent
d0b41a0f
Pipeline
#53675
failed with stage
in 26 seconds
Changes
3
Pipelines
1
Expand all
Hide whitespace changes
Inline
Side-by-side
demo.py
View file @
1ff54cfa
from
parser
import
Parser
from
objects
import
Terminal
,
Nonterminal
,
State
,
DFA
,
REG
,
NFA
from
objects
import
Character
,
Terminal
,
Nonterminal
,
State
,
DFA
,
REG
,
NFA
from
objects
import
Composition
as
comp
from
typing
import
Set
,
Dict
,
Tuple
def
make_dfa
(
states
:
Set
[
str
],
terminal
s
:
Set
[
str
],
def
make_dfa
(
states
:
Set
[
str
],
character
s
:
Set
[
str
],
transition
:
Dict
[
Tuple
[
str
,
str
],
str
],
init
:
str
,
final
:
Set
[
str
]):
dfa
=
DFA
(
set
(),
set
(),
{},
None
,
set
())
dfa
.
init
=
State
(
init
)
new_init
=
State
(
init
)
new_states
:
Set
[
State
]
=
set
()
dfa
=
DFA
(
new_states
.
add
(
new_init
),
set
(),
{},
new_init
,
set
())
for
name
in
states
:
state
=
State
(
name
)
dfa
.
states
.
add
(
state
)
for
name
in
terminal
s
:
terminal
=
Terminal
(
name
)
dfa
.
terminals
.
add
(
terminal
)
for
name
in
character
s
:
character
=
Character
(
name
)
dfa
.
characters
.
add
(
character
)
for
name
in
final
:
state
=
State
(
name
)
dfa
.
final
.
add
(
state
)
for
x
,
y
in
transition
:
state
=
State
(
x
)
terminal
=
Terminal
(
y
)
character
=
Character
(
y
)
move
=
State
(
transition
[
x
,
y
])
dfa
.
transition
[
state
,
terminal
]
=
move
dfa
.
transition
[
state
,
character
]
=
move
dfa
.
check
()
return
dfa
...
...
@@ -94,7 +97,7 @@ def main():
print
(
"Add new terminal for DFA, check its totality, then make total."
)
print
()
b
=
Terminal
(
"b"
)
dfa_1
.
terminal
s
.
add
(
b
)
dfa_1
.
character
s
.
add
(
b
)
print
(
"dfa_1.terminals.add(b), dfa_1.is_total():"
,
dfa_1
.
is_total
())
print
()
total_dfa
=
dfa_1
.
total
()
...
...
@@ -189,5 +192,13 @@ def main():
#det = nfa1.determinize()
#print(parser.dfa_to_str(det, True))
print
(
"__________________________________"
)
print
(
"DFA.is_equivalent()"
)
print
(
"Equivalence of DFAs through intersections with complements."
)
print
()
print
(
dfa_3
.
is_equivalent
(
canonical
),
", should be True"
)
print
()
main
()
\ No newline at end of file
objects.py
View file @
1ff54cfa
This diff is collapsed.
Click to expand it.
parser.py
View file @
1ff54cfa
...
...
@@ -62,15 +62,15 @@ class Parser:
# Vlada: states = ",".join(dfa.states) but I use it wrong or what
terminal
s
=
"{"
for
terminal
in
dfa
.
terminal
s
:
terminals
+=
terminal
.
name
+
","
terminals
=
terminal
s
[:
-
1
]
+
"}"
character
s
=
"{"
for
character
in
dfa
.
character
s
:
characters
+=
character
.
name
+
","
characters
=
character
s
[:
-
1
]
+
"}"
transition
=
""
for
key
,
state_2
in
dfa
.
transition
.
items
():
state_1
,
terminal
=
key
transition
+=
"("
+
state_1
.
name
+
","
+
terminal
.
name
+
")="
+
state_2
.
name
+
"
\n
"
state_1
,
character
=
key
transition
+=
"("
+
state_1
.
name
+
","
+
character
.
name
+
")="
+
state_2
.
name
+
"
\n
"
transition
=
"{"
+
transition
[:
-
1
]
+
"}"
init
=
dfa
.
init
.
name
...
...
@@ -81,7 +81,7 @@ class Parser:
final
=
final
[:
-
1
]
+
"}"
if
full
:
return
"DFA = ("
+
states
+
","
+
terminal
s
+
",d,"
+
\
return
"DFA = ("
+
states
+
","
+
character
s
+
",d,"
+
\
init
+
","
+
final
+
")
\n
"
+
"d = "
+
transition
else
:
...
...
@@ -99,10 +99,10 @@ class Parser:
# Vlada: states = ",".join(dfa.states) but I use it wrong or what
terminal
s
=
"{"
for
terminal
in
dfa
.
terminal
s
:
terminals
+=
terminal
.
name
+
","
terminals
=
terminal
s
[:
-
1
]
+
"}"
character
s
=
"{"
for
character
in
dfa
.
character
s
:
characters
+=
character
.
name
+
","
characters
=
character
s
[:
-
1
]
+
"}"
transition
=
""
for
key
,
set_states
in
dfa
.
transition
.
items
():
...
...
@@ -121,7 +121,7 @@ class Parser:
final
=
final
[:
-
1
]
+
"}"
if
full
:
return
"NFA = ("
+
states
+
","
+
terminal
s
+
",d,"
+
\
return
"NFA = ("
+
states
+
","
+
character
s
+
",d,"
+
\
init
+
","
+
final
+
")
\n
"
+
"d = "
+
transition
else
:
...
...
Write
Preview
Supports
Markdown
0%
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!
Cancel
Please
register
or
sign in
to comment