-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinterpreter.py
More file actions
31 lines (25 loc) · 1.2 KB
/
Copy pathinterpreter.py
File metadata and controls
31 lines (25 loc) · 1.2 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
class Interpreter:
def __init__(self):
self.environment = {}
def evaluate(self, node):
if isinstance(node, str):
if node.replace('.', '', 1).isdigit():
return float(node) if '.' in node else int(node)
return node
if isinstance(node, dict):
if "spawn" in node.values() and "<npc>" in node:
npc = self.evaluate(node["<npc>"])
zone = self.evaluate(node["<zone>"])
return f"SYSTEM: [{npc.upper()}] named entity loaded at the [{zone.upper()}] region."
if "set" in node.values() and "=" in node.values() and "<attribute>" in node:
attribute = self.evaluate(node["<attribute>"])
value = self.evaluate(node["<value>"])
self.environment[attribute] = value
return f"ENGINE: NPC '{attribute}' variable assigned {value} as its value. (Memory Saved)"
last_result = None
for key, value in node.items():
res = self.evaluate(value)
if res is not None:
last_result = res
return last_result
return None