示例#1
0
	def run(self):
		"The main run loop for the interpreter"
		# Run the super class run() method first off
		Interpreter.run(self)
		
		# The pointer and data array are unique to the run-time, so
		# initialise a pointer to 0 before starting interpreter:
		pointer = 0
		# and set our numbers array to all zeroes, 30,000 times over:
		arr = [0] * 30000
		
		# Should go through the program string and decide what
		# to do per-character
		# To allow iterating backwards through the string, we're
		# using i to hold the index in the string
		i = 0
		while i < len(self.program):
			# Hold the current char/command to execute in c
			c = self.program[i]
			
			try:
				# Try to execute the command here
				commands[c](self, pointer, arr, i)
			except KeyError:
				# If the command isn't found, dictionary will raise a
				# KeyError exception as the command is the key
				# We don't much mind, just ignore the key and carry on!
				pass
示例#2
0
	def __init__(self, tointerpret):
		"Initialize program with the parsed-in program string"
		# Initialise the super class
		Interpreter.__init__(self, tointerpret)
		# Make a copy of the string to interpret while first replacing
		# digits/whitespace/word characters with nothing
		program = re.sub('[\d\s\w]', '', tointerpret.lower())