def multiply(self):
     if self.RES.top is not None:
         a = self.RES.pop()[0]
         if not semantic.is_number(a):
             raise TypeError("not digit!")
     else:
         raise Exception("The Stack is empty!")
     if self.RES.top is not None:
         b = self.RES.pop()[0]
         if not semantic.is_number(b):
             raise TypeError("not digit!")
     else:
         raise Exception("The Stack is empty!")
     self.RES.push([a * b])
 def smaller_equal(self):
     if self.RES.top is not None:
         a = self.RES.pop()[0]
         if not semantic.is_number(a):
             raise TypeError("not digit!")
     else:
         raise Exception("The Stack is empty!")
     if self.RES.top is not None:
         b = self.RES.pop()[0]
         if not semantic.is_number(b):
             raise TypeError("not digit!")
     else:
         raise Exception("The Stack is empty!")
     self.RES.push([b <= a])
 def min(self):
     if self.RES.top is not None:
         a = self.RES.pop()
         for elem in a:
             if not semantic.is_number(elem):
                 raise TypeError("not digit!")
     else:
         raise Exception("The Stack is empty!")
     self.RES.push([min(a)])
 def __execute(self, commands):
     global return_commands
     try:
         command = commands.pop(0)
     except IndexError:
         return None
     if command in self.Lists:
         self.find_lists(command)
         return __execute(self, commands.copy())
     elif command in self.deref_properties:
         command = command[1:]
         assert (self.RES.isempty() is False)
         result_ids = []
         for cur in self.RES.pop():
             if type(cur) is list:
                 raise Exception("Invalid Syntax")
             succeed = 0
             self.search_in_lists(cur)
             assert (self.ENV.isempty() is False)
             attributes = self.ENV.pop()
             for attribute in attributes:
                 search_ans = self.database.search(attribute)
                 if search_ans[0] == command:
                     self.RES.push([attribute])
                     self.deref()
                     succeed = 1
                     break
             if not succeed:
                 continue
             # then recursively use the __execute
             parameters = __execute(self, commands.copy())
             bool_val = parameters[0]
             return_commands = parameters[1]
             assert (type(bool_val) is bool)
             if bool_val:
                 result_ids.append(cur)
         self.RES.push(result_ids)
         commands = return_commands
         return __execute(self, commands)
     elif command in self.function_names:
         self.functions[command]()
         return __execute(self, commands)
     elif type(command) is list:
         self.RES.push(command)
         return __execute(self, commands)
     elif semantic.is_number(command):
         self.RES.push([command])
         return __execute(self, commands)
     elif command == "where":
         assert (self.RES.isempty() is False)
         bool_val = self.RES.pop()[0]
         return [bool_val, commands]
     else:
         # plain text input
         assert (type(command) is str)
         self.RES.push([command])
         return __execute(self, commands)
 def __execute(self, commands):
     print("\n########")
     self.RES.show()
     print("########\n")
     global return_commands
     # check the command list
     try:
         command = commands.pop(0)
     except IndexError:
         return None
     if command in self.Lists:
         # push id numbers into RES
         self.find_lists(command)
         return __execute(self, commands.copy())
     elif command in self.deref_properties:
         command = command[1:]
         assert (self.RES.isempty() is False)
         result_ids = []
         # loop over the id numbers of list headers
         for cur in self.RES.pop():
             if type(cur) is list:
                 raise Exception("Invalid Syntax")
             succeed = 0
             self.search_in_lists(cur)
             assert (self.ENV.isempty() is False)
             attributes = self.ENV.pop()
             for attribute in attributes:
                 search_ans = self.database.search(attribute)
                 if search_ans[0] == command:
                     # match the attribute
                     self.RES.push([attribute])
                     self.deref()
                     succeed = 1
                     break
             if not succeed:
                 continue
             # then recursively use the __execute
             parameters = __execute(self, commands.copy())
             bool_val = parameters[0]
             return_commands = parameters[1]
             assert (type(bool_val) is bool)
             if bool_val:
                 # if True
                 result_ids.append(cur)
         self.RES.push(result_ids)
         # update command list
         commands = return_commands
         # recursion
         return __execute(self, commands)
     elif command in self.function_names:
         # detect build in functions
         self.functions[command]()
         return __execute(self, commands)
     elif type(command) is list:
         # special input like lists
         self.RES.push(command)
         return __execute(self, commands)
     elif semantic.is_number(command):
         # special input like digits
         self.RES.push([command])
         return __execute(self, commands)
     elif command == "where":
         assert (self.RES.isempty() is False)
         bool_val = self.RES.pop()[0]
         return [bool_val, commands]
     else:
         # plain text input
         assert (type(command) is str)
         self.RES.push([command])
         return __execute(self, commands)