Expression?

This commit is contained in:
Simon Forman
2022-04-04 07:58:22 -07:00
parent 6eff23b191
commit 1da997fbbf
2 changed files with 87 additions and 0 deletions
+25
View File
@@ -0,0 +1,25 @@
class Expression:
def __init__(self, initial_expression=()):
self.current = initial_expression
self.stack = []
def __next__(self):
if self.current:
item, self.current = self.current
return item
if self.stack:
self.current = self.stack.pop()
return self.__next__()
raise StopIteration
def prepend(self, quoted_program):
if self.current:
self.stack.append(self.current)
self.current = quoted_program
from parser import text_to_expression as j
e = Expression(j('23 18'))