def process(self, line, is_inside_until=False): statement = Tokenizer(line.strip(' ').strip('\n'), ' ') while statement.has_next(): token = statement.next() if token in ['.', '.s', 'CR']: if token == '.': sys.stdout.write(self.stack.pop()) self.usedWrite = True elif token == 'CR': print else: print self.stack elif token in self.memory: self.process(self.memory[token]) elif token in ['DUP', '+', '-', '*', '/', 'SWAP', 'DROP', '<', '>', '<=', '>=', '=', 'EMIT', 'MOD', 'KEY', 'DEPTH', 'ROLL', 'PICK']: import Operators Operators.Op[token](self.stack) elif token == ':': self.function_definition(statement) elif token == 'IF': self.handle_if(statement) elif token == 'DO': self.do_loop(statement) elif token == 'BEGIN': self.until_loop(statement) elif token == 'LEAVE': if is_inside_until and self.stack.pop() != '0': return False elif token == 'EXPECT': self.expect() elif token.startswith('."'): self.print_string(token, statement) elif token.isdigit(): self.stack.push(token) elif token.strip() == '': pass else: raise NameError('Invalid Input: ' + token) return True