通过函数发送列表的值
Sending a list's values through a function
我正在为我编写的编程语言创建一个简单的解释器。我正在努力做到这一点,以便您可以将多个语句放在一行中。 (如 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
是你想要的吗?
我正在为我编写的编程语言创建一个简单的解释器。我正在努力做到这一点,以便您可以将多个语句放在一行中。 (如 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
是你想要的吗?