我正在用Python开发一种迷你语言(实际上不是针对个人项目的一些命令)。
这是代码:
class FlashCard:
def __init__(self):
self.commands = {'addQuestion':self.addQuestion}
self.stack = []
self.questions = {}
def addQuestion(self):
question = self.stack.pop()
answer = input(question)
def interpret(self,expression):
for token in expression.split():
if token in self.commands:
operator = self.commands[token]
operator()
else:
self.stack.append(token)
i = FlashCard()
i.interpret('testing this addQuestion')
解释功能将仅从字符串中提取最后一个单词(this)。 有没有办法让它拉满整个生产线?
谢谢!