我正在为我制作的编程语言创建一个简单的解释器。我正在努力做到这一点,以便您可以将多个语句放在一行上。 (如 print "Hello"; print "World"
。语句之间使用分号分隔 ;
)
问题是,当我尝试在解释器中使用多个语句时出现错误。
我正在做的是获取用户输入,并用分号将其分割(这些部分进入列表)。我希望列表的值通过我拥有的 parse()
函数运行。
简而言之,我想通过函数运行列表的值。
这是我当前的代码:
if ';' in command:
semiCount = command.count(';')
command.split(';')
for i in range(0, semiCount):
command[i].replace(" ", "")
parse(command[i])
最佳答案
据我了解,你想要这个:
temp_input=raw_input() #taking the input
lst=temp_input.split(";") # splitting the input and saving in a list
for i in lst: # iterating through the list
parse(i) # calling parse() with single list element
这是你想要的吗?
关于python - 通过函数发送列表的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32997780/