-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathterminal_symbol.py
More file actions
executable file
·73 lines (57 loc) · 2.13 KB
/
terminal_symbol.py
File metadata and controls
executable file
·73 lines (57 loc) · 2.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
from intermediate_derivation import IntermediateDeriv
class TerminalSymbol(object):
"""A terminal symbol in a grammar."""
def __init__(self, representation):
"""Initialize a NonterminalSymbol object.
:param representation: string value of Terminal
:type representation: string
"""
self.representation = representation
self.markup = set()
def __eq__(self, other):
if isinstance(other, TerminalSymbol):
return self.representation == other.representation
else:
return False
def expand(self, markup=None):
"""Return this terminal symbol."""
if markup is None:
markup = set()
return IntermediateDeriv(self.markup | markup, str(self))
def monte_carlo_expand(self, markup):
"""
this is not a nonterminal, so the monte carlo_expand is the same as the normal expand
"""
return self.expand(markup)
def exhaustively_and_nonprobabilistically_expand(self, markup):
return self.expand(markup=markup)
def n_terminal_expansions(self):
"""Return the number of possible terminal expansions of this symbol."""
return 1
def __str__(self):
return self.representation.__str__()
def __repr__(self):
return self.__str__()
class SystemVar(TerminalSymbol):
"""
class to handle systemVariables which are processed by game engine
instead of Expressionist, separate from TerminalSymbol so that
we can provide a list of all systemVar easily
"""
def __init__(self, representation):
TerminalSymbol.__init__(self, representation)
def __str__(self):
return "[" + str(self.representation) + "]"
def __repr__(self):
return self.__str__()
def __cmp__(self, other):
# ughhh
if isinstance(other, SystemVar):
if str(self) < str(other): # compare name value (should be unique)
return -1
elif str(self) > str(other):
return 1
else:
return 0 # should mean it's the same instance
else:
return 0