3 ms·
I copied the response verbatim. I also did a follow-up where it wrote the interpreter as well: class KimmieInterpreter: def __init__(self):
by localhost 4y ago
I copied the response verbatim. I also did a follow-up where it wrote the interpreter as well:
class KimmieInterpreter:
def __init__(self):
self.variables = {}
def interpret(self, code):
for line in code.split("\n"):
tokens = line.split()
if len(tokens) == 0:
continue
if tokens[0] == "#":
self.variables[tokens[1]] = None
elif tokens[0] == "#my_var":
self.variables[tokens[1]] = int(tokens[3])
elif tokens[0] == "OMG":
print(tokens[1][1:-1])
elif tokens[0] == "add":
var1 = self.variables[tokens[2]]
var2 = self.variables[tokens[3]]
result = var1 + var2
self.variables[tokens[1]] = result