def tokenize(self, statement): if not isinstance(statement, string_types): return False dcec_container = DCECContainer() stuff = high_level_parsing.tokenize_random_dcec(statement, self.namespace) if isinstance(stuff[0], bool) and not stuff[0]: return False elif stuff[0] == "": return True dcec_container.stupid_loop(stuff[0], stuff[3], stuff[2], self) dcec_container.add_statement(statement) return dcec_container
def tokenize(self, statement): if not isinstance(statement, string_types): return False dcec_container = DCECContainer() stuff = high_level_parsing.tokenize_random_dcec( statement, self.namespace) if isinstance(stuff[0], bool) and not stuff[0]: return False elif stuff[0] == "": return True dcec_container.stupid_loop(stuff[0], stuff[3], stuff[2], self) dcec_container.add_statement(statement) return dcec_container
def add_statement(self, statement): """ Given a statement, attempts to parse the statement into the DCEC*. If there's an issue, it'll print the issue and then return False, otherwise it'll return True and add the statement to the Container instance :param statement: :return: """ add_atomics = {} add_functions = {} add_quants = {} addee = statement if isinstance(addee, string_types): addee, add_quants, \ add_atomics, add_functions = high_level_parsing.tokenize_random_dcec(addee, self.namespace) if isinstance(addee, bool) and not addee: print("ERROR: the statement " + str(statement) + " was not correctly formed.") return False elif addee == "": return True elif isinstance(addee, high_level_parsing.Token): pass else: print("ERROR: the input " + str(statement) + " was not of the correct type.") return False for atomic in add_atomics.keys(): # Tokens are not currently stored if isinstance(atomic, high_level_parsing.Token): continue for potentialtype in range(0, len(add_atomics[atomic])): if (not self.namespace.no_conflict(add_atomics[atomic][0], add_atomics[atomic][potentialtype], 0)[0]) and \ (not self.namespace.no_conflict(add_atomics[atomic][potentialtype], add_atomics[atomic][0], 0)[0]): print( "ERROR: The atomic " + atomic + " cannot be both " + add_atomics[atomic][potentialtype] + " and " + add_atomics[atomic][0] + ". (This is caused by assigning different sorts to two atomics inline. " "Did you rely on the parser for sorting?)") return False for function in add_functions.keys(): for item in add_functions[function]: if item[0] == "?": print( "ERROR: please define the returntype of the inline function " + function) return False else: self.namespace.add_code_function(function, item[0], item[1]) for atomic in add_atomics.keys(): # Tokens are not currently stored if isinstance(atomic, high_level_parsing.Token): continue elif atomic in self.namespace.atomics.keys(): if not self.namespace.no_conflict(self.namespace.atomics[atomic], add_atomics[atomic][0], 0)[0] and \ not self.namespace.no_conflict(add_atomics[atomic][0], self.namespace.atomics[atomic], 0)[0]: print("ERROR: The atomic " + atomic + " cannot be both " + add_atomics[atomic][0] + " and " + self.namespace.atomics[atomic] + ".") return False else: self.namespace.add_code_atomic(atomic, add_atomics[atomic][0]) for quant in add_quants.keys(): if 'QUANT' in quant: self.namespace.quant_map[quant] = add_quants[quant] self.statements.append(addee) if not isinstance(addee, string_types): self.checkMap[addee.create_s_expression()] = addee else: self.checkMap[addee] = addee return True
def add_statement(self, statement): """ Given a statement, attempts to parse the statement into the DCEC*. If there's an issue, it'll print the issue and then return False, otherwise it'll return True and add the statement to the Container instance :param statement: :return: """ add_atomics = {} add_functions = {} add_quants = {} addee = statement if isinstance(addee, string_types): addee, add_quants, \ add_atomics, add_functions = high_level_parsing.tokenize_random_dcec(addee, self.namespace) if isinstance(addee, bool) and not addee: print("ERROR: the statement " + str(statement) + " was not correctly formed.") return False elif addee == "": return True elif isinstance(addee, high_level_parsing.Token): pass else: print("ERROR: the input " + str(statement) + " was not of the correct type.") return False for atomic in add_atomics.keys(): # Tokens are not currently stored if isinstance(atomic, high_level_parsing.Token): continue for potentialtype in range(0, len(add_atomics[atomic])): if (not self.namespace.no_conflict(add_atomics[atomic][0], add_atomics[atomic][potentialtype], 0)[0]) and \ (not self.namespace.no_conflict(add_atomics[atomic][potentialtype], add_atomics[atomic][0], 0)[0]): print("ERROR: The atomic " + atomic + " cannot be both " + add_atomics[atomic][potentialtype] + " and " + add_atomics[atomic][0] + ". (This is caused by assigning different sorts to two atomics inline. " "Did you rely on the parser for sorting?)") return False for function in add_functions.keys(): for item in add_functions[function]: if item[0] == "?": print("ERROR: please define the returntype of the inline function " + function) return False else: self.namespace.add_code_function(function, item[0], item[1]) for atomic in add_atomics.keys(): # Tokens are not currently stored if isinstance(atomic, high_level_parsing.Token): continue elif atomic in self.namespace.atomics.keys(): if not self.namespace.no_conflict(self.namespace.atomics[atomic], add_atomics[atomic][0], 0)[0] and \ not self.namespace.no_conflict(add_atomics[atomic][0], self.namespace.atomics[atomic], 0)[0]: print("ERROR: The atomic "+atomic+" cannot be both " + add_atomics[atomic][0] + " and " + self.namespace.atomics[atomic] + ".") return False else: self.namespace.add_code_atomic(atomic, add_atomics[atomic][0]) for quant in add_quants.keys(): if 'QUANT' in quant: self.namespace.quant_map[quant] = add_quants[quant] self.statements.append(addee) if not isinstance(addee, string_types): self.checkMap[addee.create_s_expression()] = addee else: self.checkMap[addee] = addee return True