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
5c8882ec
Verified
Commit
5c8882ec
authored
Mar 25, 2020
by
Vladimír Štill
Browse files
CFL: Use Terminal and Nonterminal from common in cfl
parent
bd1b9bc0
Changes
2
Hide whitespace changes
Inline
Side-by-side
cfl.py
View file @
5c8882ec
...
...
@@ -4,46 +4,11 @@ from typing import Set, Dict, List, Union, Optional, Tuple, Iterable, \
import
typing
from
typing_extensions
import
Final
from
copy
import
deepcopy
from
common
import
Terminal
,
Nonterminal
T
=
TypeVar
(
"T"
)
class
Terminal
:
def
__init__
(
self
,
name
:
str
):
self
.
name
=
name
def
__eq__
(
self
,
obj
):
if
isinstance
(
obj
,
Terminal
):
return
obj
.
name
==
self
.
name
return
False
def
__hash__
(
self
):
return
hash
(
self
.
name
)
def
__repr__
(
self
)
->
str
:
return
f
"Terminal(
{
self
.
name
}
)"
class
Nonterminal
:
def
__init__
(
self
,
name
:
str
):
self
.
name
=
name
def
__eq__
(
self
,
obj
):
if
isinstance
(
obj
,
Nonterminal
):
return
obj
.
name
==
self
.
name
return
False
def
__hash__
(
self
):
return
hash
(
self
.
name
)
def
__lt__
(
self
,
other
:
Nonterminal
)
->
bool
:
return
self
.
name
<
other
.
name
def
__repr__
(
self
)
->
str
:
return
f
"Nonterminal(
{
self
.
name
}
)"
def
all_of
(
pred
:
Callable
[[
T
],
bool
],
it
:
Iterable
[
T
])
->
bool
:
return
all
(
map
(
pred
,
it
))
...
...
common.py
View file @
5c8882ec
...
...
@@ -12,6 +12,9 @@ class Terminal:
def
__hash__
(
self
):
return
hash
(
self
.
name
)
def
__repr__
(
self
)
->
str
:
return
f
"Terminal(
{
self
.
name
}
)"
class
Nonterminal
:
def
__init__
(
self
,
name
:
str
):
...
...
@@ -25,6 +28,9 @@ class Nonterminal:
def
__hash__
(
self
):
return
hash
(
self
.
name
)
def
__repr__
(
self
)
->
str
:
return
f
"Nonterminal(
{
self
.
name
}
)"
class
Character
:
def
__init__
(
self
,
name
:
str
):
...
...
@@ -71,4 +77,4 @@ class Emptyset:
return
isinstance
(
other
,
Eps
)
def
__hash__
(
self
):
return
hash
(
"∅"
)
\ No newline at end of file
return
hash
(
"∅"
)
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