Esempio n. 1
0
 def addStatement(self, statement):
     addAtomics = {}
     addFunctions = {}
     addQuants = {}
     addee = statement
     if isinstance(addee, str):
         addee, addQuants, addAtomics, addFunctions = highLevelParsing.tokenizeRandomDCEC(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, highLevelParsing.Token):
         pass
     else:
         print "ERROR: the input " + str(statement) + " was not of the correct type."
         return False
     for atomic in addAtomics.keys():
         if isinstance(atomic, highLevelParsing.Token):
             continue  # Tokens are not currently stored
         for potentialtype in range(0, len(addAtomics[atomic])):
             if (not self.namespace.noConflict(addAtomics[atomic][0], addAtomics[atomic][potentialtype], 0)[0]) and (
                 not self.namespace.noConflict(addAtomics[atomic][potentialtype], addAtomics[atomic][0], 0)[0]
             ):
                 print "ERROR: The atomic " + atomic + " cannot be both " + addAtomics[atomic][
                     potentialtype
                 ] + " and " + addAtomics[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 addFunctions.keys():
         for item in addFunctions[function]:
             if item[0] == "?":
                 print "ERROR: please define the returntype of the inline function " + function
                 return False
             else:
                 self.namespace.addCodeFunction(function, item[0], item[1])
     for atomic in addAtomics.keys():
         if isinstance(atomic, highLevelParsing.Token):
             continue  # Tokens are not currently stored
         elif atomic in self.namespace.atomics.keys():
             if (not self.namespace.noConflict(self.namespace.atomics[atomic], addAtomics[atomic][0], 0)[0]) and (
                 not self.namespace.noConflict(addAtomics[atomic][0], self.namespace.atomics[atomic], 0)[0]
             ):
                 print "ERROR: The atomic " + atomic + " cannot be both " + addAtomics[atomic][
                     0
                 ] + " and " + self.namespace.atomics[atomic] + "."
                 return False
         else:
             self.namespace.addCodeAtomic(atomic, addAtomics[atomic][0])
     for quant in addQuants.keys():
         if "QUANT" in quant:
             self.namespace.quantMap[quant] = addQuants[quant]
     self.statements.append(addee)
     if not isinstance(addee, str):
         self.checkMap[addee.createSExpression()] = addee
     else:
         self.checkMap[addee] = addee
     return True
 def tokenize(self,statement):
     if not isinstance(statement,str):
         return False
     dcecContainer=DCECContainer()
     stuff=highLevelParsing.tokenizeRandomDCEC(statement,self.namespace)
     if isinstance(stuff,bool) and not stuff:
         return False
     dcecContainer.stupidLoop(stuff[0],stuff[3],stuff[2],self)
     dcecContainer.addStatement(statement)
     return dcecContainer
Esempio n. 3
0
 def tokenize(self,statement):
     if not isinstance(statement,str):
         return False
     dcecContainer=DCECContainer()
     stuff=highLevelParsing.tokenizeRandomDCEC(statement,self.namespace)
     if isinstance(stuff[0],bool) and not stuff[0]:
         return False
     elif stuff[0] == "":
         return True
     dcecContainer.stupidLoop(stuff[0],stuff[3],stuff[2],self)
     dcecContainer.addStatement(statement)
     return dcecContainer
Esempio n. 4
0
 def addStatement(self,statement):
     addAtomics = {}
     addFunctions = {}
     addQuants = {}
     addee = statement
     if isinstance(addee,str):
         addee,addQuants,addAtomics,addFunctions = highLevelParsing.tokenizeRandomDCEC(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,highLevelParsing.Token):
         pass
     else:
         print "ERROR: the input "+str(statement)+" was not of the correct type."
         return False
     for atomic in addAtomics.keys():
         if isinstance(atomic,highLevelParsing.Token): continue #Tokens are not currently stored
         for potentialtype in range(0,len(addAtomics[atomic])):
             if (not self.namespace.noConflict(addAtomics[atomic][0],addAtomics[atomic][potentialtype],0)[0]) and (not self.namespace.noConflict(addAtomics[atomic][potentialtype],addAtomics[atomic][0],0)[0]):
                 print "ERROR: The atomic "+atomic+" cannot be both "+addAtomics[atomic][potentialtype]+" and "+addAtomics[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 addFunctions.keys():
         for item in addFunctions[function]:
             if item[0] == "?":
                 print "ERROR: please define the returntype of the inline function "+function
                 return False
             else:
                 self.namespace.addCodeFunction(function,item[0],item[1])         
     for atomic in addAtomics.keys():
         if isinstance(atomic,highLevelParsing.Token): continue #Tokens are not currently stored
         elif atomic in self.namespace.atomics.keys():
             if (not self.namespace.noConflict(self.namespace.atomics[atomic],addAtomics[atomic][0],0)[0]) and (not self.namespace.noConflict(addAtomics[atomic][0],self.namespace.atomics[atomic],0)[0]):
                 print "ERROR: The atomic "+atomic+" cannot be both "+addAtomics[atomic][0]+" and "+self.namespace.atomics[atomic]+"."
                 return False
         else:
             self.namespace.addCodeAtomic(atomic,addAtomics[atomic][0])    
     for quant in addQuants.keys():
         if 'QUANT' in quant:
             self.namespace.quantMap[quant] = addQuants[quant]
     self.statements.append(addee)
     if not isinstance(addee,str):
         self.checkMap[addee.createSExpression()] = addee
     else:
         self.checkMap[addee] = addee
     return True