Пример #1
0
 def fnCall(self, name, args):
     """Calls a function given its name and arguments."""
     if name in self.function_table:
         return self.function_table[name](*args)
     # user defined function: insert code to execute in tokens
     fn = self.user_function_table[name]
     for x in fn[1]:
         if x[1] == TokenType.Var:
             index = find(x[0], fn[0])
             if index == None:
                 # TODO: ERROR
                 pass
             self._tokens.insert(0, self.getArgTuple(args[index]))
         else:
             self._tokens.insert(0, x)
     return self.interpretStatement() 
Пример #2
0
 def interpret(self, tokens):
     """ Interprets a (multi-line) program. """
     self.loadUserFunctions()
     last, end_token = 0, (";", TokenType.End)
     find_end = lambda: find(end_token, tokens[last:]) + last + 1
     output = []
     amount = tokens.count(end_token)
     for i in range(amount):
         new = find_end()
         try:
             self._tokens = tokens[last:new]
             output.append(self.interpretStatement())
         except:
             output.append("Oops, seems like something went wrong.")
             raise
         last, new = new, find_end()
     self.saveUserFunctions()
     return output