Beispiel #1
0
def tokenizeRandomDCEC(expression, namespace=""):
    '''
    This function creates a token representation of a random DCEC statement.
    It returns the token as well as sorts of new atomics and functions.
    '''
    #Default DCEC Functions
    if namespace == "":
        namespace = prototypes.NAMESPACE()
        namespace.addBasicDCEC()
    else:
        namespace = namespace
    #Remove Comments
    temp = removeComments(expression)
    #Check for an empty string
    if temp == "()":
        return ("", {}, {}, {})
    #Check for a parentheses mismatch error
    if not cleaning.checkParens(expression):
        print "ERROR: parentheses mismatch error."
        return (False, False, False, False)
    #Make symbols into functions
    temp = functorizeSymbols(temp)
    #Strip comments
    temp = cleaning.stripComments(temp)
    #Strip whitespace so you can do the rest of the parsing
    temp = cleaning.stripWhiteSpace(temp)
    #Tuck the functions inside thier parentheses
    temp = cleaning.tuckFunctions(temp)
    #Strip whitespace again
    temp = cleaning.stripWhiteSpace(temp)
    #Consolidate Parentheses
    temp = cleaning.consolidateParens(temp)
    quantifiers = []
    #These are the tokens that should be added to the namespace
    addAtomics = {}
    addFunctions = {}
    addQuants = {}
    returnToken = TokenTree(temp, namespace, quantifiers, addQuants,
                            addAtomics, addFunctions)
    #check for errors that occur in the lower level
    if isinstance(returnToken, bool) and returnToken == False:
        return (False, False, False, False)
    #Add quantifiers to the TokenTree
    returnToken = tokenizeQuantifiers(returnToken, quantifiers)
    return (returnToken, addQuants, addAtomics, addFunctions)
def tokenizeRandomDCEC(expression,namespace = ""):
    '''
    This function creates a token representation of a random DCEC statement.
    It returns the token as well as sorts of new atomics and functions.
    '''
    #Default DCEC Functions
    if namespace == "":
        namespace = prototypes.NAMESPACE()
        namespace.addBasicDCEC()
    else:
        namespace = namespace
    #Remove Comments
    temp = removeComments(expression)
    #Check for an empty string
    if temp == "()":
        return ("",{},{},{})
    #Check for a parentheses mismatch error
    if not cleaning.checkParens(expression):
        print "ERROR: parentheses mismatch error."
        return (False,False,False,False)
    #Make symbols into functions
    temp = functorizeSymbols(temp)
    #Strip comments
    temp = cleaning.stripComments(temp)
    #Strip whitespace so you can do the rest of the parsing
    temp = cleaning.stripWhiteSpace(temp)
    #Tuck the functions inside thier parentheses
    temp = cleaning.tuckFunctions(temp)
    #Strip whitespace again
    temp = cleaning.stripWhiteSpace(temp)
    #Consolidate Parentheses
    temp = cleaning.consolidateParens(temp)
    quantifiers = []
    #These are the tokens that should be added to the namespace
    addAtomics = {}
    addFunctions = {}
    addQuants = {}
    returnToken = TokenTree(temp,namespace,quantifiers,addQuants,addAtomics,addFunctions)
    #check for errors that occur in the lower level
    if isinstance(returnToken,bool) and returnToken == False:
        return (False,False,False,False)
    #Add quantifiers to the TokenTree
    returnToken = tokenizeQuantifiers(returnToken,quantifiers)
    return (returnToken,addQuants,addAtomics,addFunctions)
Beispiel #3
0
    returnToken = tokenizeQuantifiers(returnToken, quantifiers)
    return (returnToken, addQuants, addAtomics, addFunctions)


if __name__ == "__main__":
    '''
    Testing suite.
    '''
    inputin = raw_input("Enter an expression: ")
    #Make symbols into functions
    temp = removeComments(inputin)
    print temp
    temp = functorizeSymbols(temp)
    print temp
    #Strip comments
    temp = cleaning.stripComments(temp)
    print temp
    #Strip whitespace so you can do the rest of the parsing
    temp = cleaning.stripWhiteSpace(temp)
    print temp
    #Tuck the functions inside thier parentheses
    temp = cleaning.tuckFunctions(temp)
    print temp
    #Consolidate Parentheses
    temp = cleaning.consolidateParens(temp)
    print temp
    testNAMESPACE = prototypes.NAMESPACE()
    testNAMESPACE.addBasicDCEC()
    testNAMESPACE.addBasicNumerics()
    testNAMESPACE.addBasicLogic()
    testNAMESPACE.addTextFunction("ActionType heal Agent")
    #Add quantifiers to the TokenTree
    returnToken = tokenizeQuantifiers(returnToken,quantifiers)
    return (returnToken,addQuants,addAtomics,addFunctions)
        
if __name__ == "__main__":
    '''
    Testing suite.
    '''
    inputin = raw_input("Enter an expression: ")
    #Make symbols into functions
    temp = removeComments(inputin)
    print temp
    temp = functorizeSymbols(temp)
    print temp
    #Strip comments
    temp = cleaning.stripComments(temp)
    print temp
    #Strip whitespace so you can do the rest of the parsing
    temp = cleaning.stripWhiteSpace(temp)
    print temp
    #Tuck the functions inside thier parentheses
    temp = cleaning.tuckFunctions(temp)
    print temp
    #Consolidate Parentheses
    temp = cleaning.consolidateParens(temp)
    print temp
    testNAMESPACE = prototypes.NAMESPACE()
    testNAMESPACE.addBasicDCEC()
    testNAMESPACE.addBasicNumerics()
    testNAMESPACE.addBasicLogic()
    testNAMESPACE.addTextFunction("ActionType heal Agent")