1
0
Fork 0
mirror of https://github.com/Lyxal/Keta.git synced 2024-08-14 23:53:13 +00:00
Keta/ekg/Code_Token.py
2020-01-04 19:18:18 +11:00

35 lines
1,018 B
Python

class Code_Token():
def __init__(self, function, left, right):
'''
function: a callable function object
left: the left argument (if applicable)
right: the right argument
'''
self.fn = function
self.left_arg = left
self.right_arg = right
def execute(self, surrounds=None):
if self.left_arg == Relative_Argument:
if surrounds:
self.left_arg = surrounds[0]
else:
self.left_arg = eval(input())
if self.right_arg == Relative_Argument:
if surrounds:
self.right_arg = surrounds[-1]
else:
self.right_arg = eval(input())
if type(self.left_arg) == Code_Token:
self.left_arg = self.left_arg.execute()
if type(self.right_arg) == Code_Token:
self.right_arg = self.right_arg.execute()
return self.fn(self.left_arg, self.right_arg)
class Relative_Argument:
pass