コード例 #1
0
ファイル: interp_2.py プロジェクト: AdamBanham/TILDE-ATH
def getCharObj(theChar):
    if(theChar in charObjs):
        return charObjs[theChar]
    else:
        theCharObj=bif.value_obj()
        charObjs[theChar]=theCharObj
        return theCharObj
コード例 #2
0
ファイル: interp_2.py プロジェクト: Aquamace11/TILDE-ATH
def getCharObj(theChar):
    if(theChar in charObjs):
        return charObjs[theChar]
    else:
        theCharObj=bif.value_obj()
        charObjs[theChar]=theCharObj
        return theCharObj
コード例 #3
0
ファイル: interp_2.py プロジェクト: AdamBanham/TILDE-ATH
def evalScript(script,inObj):
    ATHVars={}
    THIS=bif.value_obj()
    ATHVars['THIS']=THIS
    ATHVars['NULL']=NULL_obj
    ATHVars['ARGS']=inObj
    return_obj=NULL_obj

    charNum=0
    execStack=[]

    while(THIS.living):
        if(False):
            pass
        elif(script.startswith('import ',charNum)):
            semicolonOffset=script[charNum:].index(';')
            importStatementStr=script[charNum:charNum+semicolonOffset]
            importStatementList=importStatementStr.split(' ')
            if(importStatementList[-1] not in ATHVars):
                ATHVars[importStatementList[-1]]=bif.value_obj()
            charNum+=semicolonOffset
        elif(re.match(r'importf ([^; ]+) as ([^; ]+);',script[charNum:])!=None):
            matches=re.match(r'importf ([^; ]+) as ([^; ]+);',script[charNum:])
            importfFilename=matches.group(1)
            #print "the filename is "+importfFilename
            try:
                importfFilelink=open(importfFilename,'r')
                newFunc=importfFilelink.read(-1)
                #print newFunc
                funCodes[matches.group(2)]=newFunc
            except:
                print ("could not read file "+importfFilename)
            charNum=script.find(';',charNum)   
        elif(script.startswith('~ATH(',charNum)):
            closeparenOffset=script[charNum:].index(')')
            loopVar=script[charNum+5:charNum+closeparenOffset]
            loopVar=loopVar.strip(' \t\n\r')
            #print "reached ~ATH command, loopVar is "+loopVar
            if(loopVar in ATHVars):
                if(ATHVars[loopVar].living):
                    execStack.append((charNum,'{'))
                    charNum+=closeparenOffset
                    #print "loop on "+loopVar
                else:
                    #print "parenmatch jump from "+str(charNum)
                    charNum=matchParens(script,charNum,'{','}')+2
                    #print "parenmatch jumped to char:"+str(charNum)+" which was"+script[charNum]
                    #print "loopVar was "+loopVar
            else:
                print('warning/error: \"{0}\" is undefined'.format(loopVar))
        elif(script.startswith('}',charNum)):
            openingTuple=execStack.pop()
            if(openingTuple[1]=='{'):
                charNum=openingTuple[0]
            else:
                print('what are you trying to do? \"(...}\" error')
        elif(script.startswith('print ',charNum)):
            #print "print..."
            semicolonOffset=script[charNum:].index(';')
            print(script[charNum+6:charNum+semicolonOffset])
            charNum+=semicolonOffset#+6
        elif(re.match(r'PRINT2 ([^\[\];]*);',script[charNum:])!=None):
            matches=re.match(r'PRINT2 ([^\[\];]*);',script[charNum:])
            print (getObjStr(ATHVars[matches.group(1)]))
            charNum=script.find(';',charNum)
        elif(script.startswith('INPUT',charNum)):
            semicolonOffset=script[charNum:].index(';')
            varname=script[charNum+6:charNum+semicolonOffset]
            #print 'INPUT varname was "'+varname+'"'
            ATHVars[varname]=getStrObj(input(':'))
            charNum+=semicolonOffset
        elif(re.match(r'BIFURCATE ([^\[\];]*)\[([^\[\];]*),([^\[\];]*)\];',script[charNum:])!=None):
            #print("binurcate the thing!")
            matches=re.match(r'BIFURCATE ([^\[\];]*)\[([^\[\];]*),([^\[\];]*)\];',script[charNum:])
            (ATHVars[matches.group(2)],ATHVars[matches.group(3)])=bifurcate(ATHVars[matches.group(1)])
            charNum=script.find(';',charNum)
        elif(re.match(r'BIFURCATE \[([^\[\];]*),([^\[\];]*)\]([^\[\];]*);',script[charNum:])!=None):
            matches=re.match(r'BIFURCATE \[([^\[\];]*),([^\[\];]*)\]([^\[\];]*);',script[charNum:])
            ATHVars[matches.group(3)]=bifurcate(ATHVars[matches.group(1)],ATHVars[matches.group(2)])
            charNum=script.find(';',charNum)
        elif(script.startswith('BIFFURCATE ',charNum)):
            charNum+=10
            semicolonOffset=script[charNum:].index(';')
            openSquareOffset=script[charNum:].index('[')
            closeSquareOffset=script[charNum:].index(']')
            commaOffset=script[charNum:].index(',')
            syntacticallyCorrect=True
            for offset in [openSquareOffset,closeSquareOffset,commaOffset]:
                if((offset==-1) or (offset>semicolonOffset)):
                    print("Bifurcate command malformed, char:"+str(charNum))
                    syntacticallyCorrect=False
                    break
            if(syntacticallyCorrect):
                if(openSquareOffset==0):
                    leftHalf=script[charNum+openSquareOffset+1:charNum+commaOffset]
                    rightHalf=script[charNum+commaOffset+1:charNum+closeSquareOffset]
                    combinedName=script[charNum+closeSquareOffset+1:charNum+semicolonOffset]
                    ATHVars[combinedName]=bifurcate(ATHVars[leftHalf],ATHVars[rightHalf])
                else:
                    toSplitName=script[charNum:charNum+openSquareOffset]
                    leftHalf=script[charNum+openSquareOffset+1:charNum+commaOffset]
                    rightHalf=script[charNum+commaOffset+1:charNum+closeSquareOffset]
                    (ATHVars[leftHalf],ATHVars[rightHalf])=bifurcate(ATHVars[toSplitName])
        elif(re.match(r'([0-9a-zA-Z]+)\.DIE\(([0-9a-zA-Z]*)\);',script[charNum:])!=None):#script[charNum:script[charNum:].find(';')].endswith('.DIE()')):
            matches=re.match(r'([0-9a-zA-Z]+)\.DIE\(([0-9a-zA-Z]*)\);',script[charNum:])#.group(1)
            varname=matches.group(1)
            argvarname=matches.group(2)
            if argvarname:
                #print("argvarname is " +argvarname)
                return_obj=ATHVars[argvarname]
            #print "found .DIE(); statement! Variable name is "+varname
            ATHVars[varname].DIE()
            charNum=script.find(';',charNum)
            #print varname+"killed"
        elif(script.startswith('//',charNum)):
            nextNewlinePos=script.find('\n',charNum)
            if '\r' in script[charNum:nextNewlinePos]:
                nextNewlinePos=script.find('\r',charNum)
            charNum=nextNewlinePos
        elif(script.startswith('/*',charNum)):
            charNum=script.find('*/',charNum)
        elif(script.startswith('PYDEBUG',charNum)):
            pdb.set_trace()
            charNum+=5
        elif(re.match(r'([A-Z0-9_]+) \[([^\[\];]*),([^\[\];]*)\]([^\[\];]*);',script[charNum:])!=None):
            try:
                matches=re.match(r'([A-Z0-9_]+) \[([^\[\];]*),([^\[\];]*)\]([^\[\];]*);',script[charNum:])
                funName=matches.group(1)
                #print "the function called '"+funName + "' was called."
                #print "yeah it works."
                if funName in funCodes:
                    theFuncCode=funCodes[funName]
                    sentInObject=bifurcate(ATHVars[matches.group(2)],ATHVars[matches.group(3)])
                    ATHVars[matches.group(4)]=evalScript(theFuncCode,sentInObject)
                else:
                    print ("error: function called '"+funName+"' not recognized")
                charNum+=len(funName)
            except:
                print ("function not recognized/ a bug in the interpreter")
                print (matches)#re.match(r'([A-Z0-9_]+) \[([^\[\];]*),([^\[\];]*)\]([^\[\];]*);',script[charNum:])
                print ("...")
                charNum+=1
            #charNum+=1
        elif(re.match(r'([A-Z0-9_]+) ([^\[\];]*)\[([^\[\];]*),([^\[\];]*)\];',script[charNum:])!=None):
            try:
                matches=re.match(r'([A-Z0-9_]+) ([^\[\];]*)\[([^\[\];]*),([^\[\];]*)\];',script[charNum:])
                funName=matches.group(1)
                #print "the function called '"+funName + "' was called."
                #print "yeah it works."
                if funName in funCodes:
                    theFuncCode=funCodes[funName]
                    sentInObject=ATHVars[matches.group(2)]#bifurcate(ATHVars[matches.group(2)],ATHVars[matches.group(3)])
                    ATHVars[matches.group(3)],ATHVars[matches.group(4)]=bifurcate(evalScript(theFuncCode,sentInObject))
                else:
                    print ("error: function called '"+funName+"' not recognized")
                charNum+=len(funName)
            except:
                print ("function not recognized/ a bug in the interpreter")
                print (matches)#re.match(r'([A-Z0-9_]+) \[([^\[\];]*),([^\[\];]*)\]([^\[\];]*);',script[charNum:])
                print ("...")
                charNum+=1
        else:
             charNum+=1
             if(charNum > len(script)):
                 THIS.DIE()
        #print script[charNum]
    return return_obj
コード例 #4
0
ファイル: interp_2.py プロジェクト: AdamBanham/TILDE-ATH
BIFURCATE [BLAH,C]C;
}
/*
BIFURCATE [BLAH,C]CTEMP;
BIFURCATE CTEMP[JUNK,CTEMP];
~ATH(CTEMP){
BIFURCATE CTEMP[JUNK,CTEMP];
print some text;
}
print DONE!;
*/
THIS.DIE(C);
"""#NOTE:use a better addition algorithm.


NULL_obj=bif.value_obj()
NULL_obj.DIE()
def evalScript(script,inObj):
    ATHVars={}
    THIS=bif.value_obj()
    ATHVars['THIS']=THIS
    ATHVars['NULL']=NULL_obj
    ATHVars['ARGS']=inObj
    return_obj=NULL_obj

    charNum=0
    execStack=[]

    while(THIS.living):
        if(False):
            pass
コード例 #5
0
ファイル: interp_2.py プロジェクト: Aquamace11/TILDE-ATH
def evalScript(script,inObj):
    ATHVars={}
    THIS=bif.value_obj()
    ATHVars['THIS']=THIS
    ATHVars['NULL']=NULL_obj
    ATHVars['ARGS']=inObj
    return_obj=NULL_obj

    charNum=0
    execStack=[]

    while(THIS.living):
        if(False):
            pass
        elif(script.startswith('import ',charNum)):
            semicolonOffset=script[charNum:].index(';')
            importStatementStr=script[charNum:charNum+semicolonOffset]
            importStatementList=importStatementStr.split(' ')
            if(importStatementList[-1] not in ATHVars):
                ATHVars[importStatementList[-1]]=bif.value_obj()
            charNum+=semicolonOffset
        elif(re.match(r'importf ([^; ]+) as ([^; ]+);',script[charNum:])!=None):
            matches=re.match(r'importf ([^; ]+) as ([^; ]+);',script[charNum:])
            importfFilename=matches.group(1)
            #print "the filename is "+importfFilename
            try:
                importfFilelink=open(importfFilename,'r')
                newFunc=importfFilelink.read(-1)
                #print newFunc
                funCodes[matches.group(2)]=newFunc
            except:
                print "could not read file "+importfFilename
            charNum=script.find(';',charNum)   
        elif(script.startswith('~ATH(',charNum)):
            closeparenOffset=script[charNum:].index(')')
            loopVar=script[charNum+5:charNum+closeparenOffset]
            loopVar=loopVar.strip(' \t\n\r')
            #print "reached ~ATH command, loopVar is "+loopVar
            if(loopVar in ATHVars):
                if(ATHVars[loopVar].living):
                    execStack.append((charNum,'{'))
                    charNum+=closeparenOffset
                    #print "loop on "+loopVar
                else:
                    #print "parenmatch jump from "+str(charNum)
                    charNum=matchParens(script,charNum,'{','}')+2
                    #print "parenmatch jumped to char:"+str(charNum)+" which was"+script[charNum]
                    #print "loopVar was "+loopVar
            else:
                print('warning/error: \"{0}\" is undefined'.format(loopVar))
        elif(script.startswith('}',charNum)):
            openingTuple=execStack.pop()
            if(openingTuple[1]=='{'):
                charNum=openingTuple[0]
            else:
                print('what are you trying to do? \"(...}\" error')
        elif(script.startswith('print ',charNum)):
            #print "print..."
            semicolonOffset=script[charNum:].index(';')
            print(script[charNum+6:charNum+semicolonOffset])
            charNum+=semicolonOffset#+6
        elif(re.match(r'PRINT2 ([^\[\];]*);',script[charNum:])!=None):
            matches=re.match(r'PRINT2 ([^\[\];]*);',script[charNum:])
            print getObjStr(ATHVars[matches.group(1)])
            charNum=script.find(';',charNum)
        elif(script.startswith('INPUT',charNum)):
            semicolonOffset=script[charNum:].index(';')
            varname=script[charNum+6:charNum+semicolonOffset]
            #print 'INPUT varname was "'+varname+'"'
            ATHVars[varname]=getStrObj(raw_input(':'))
            charNum+=semicolonOffset
        elif(re.match(r'BIFURCATE ([^\[\];]*)\[([^\[\];]*),([^\[\];]*)\];',script[charNum:])!=None):
            #print("binurcate the thing!")
            matches=re.match(r'BIFURCATE ([^\[\];]*)\[([^\[\];]*),([^\[\];]*)\];',script[charNum:])
            (ATHVars[matches.group(2)],ATHVars[matches.group(3)])=bifurcate(ATHVars[matches.group(1)])
            charNum=script.find(';',charNum)
        elif(re.match(r'BIFURCATE \[([^\[\];]*),([^\[\];]*)\]([^\[\];]*);',script[charNum:])!=None):
            matches=re.match(r'BIFURCATE \[([^\[\];]*),([^\[\];]*)\]([^\[\];]*);',script[charNum:])
            ATHVars[matches.group(3)]=bifurcate(ATHVars[matches.group(1)],ATHVars[matches.group(2)])
            charNum=script.find(';',charNum)
        elif(script.startswith('BIFFURCATE ',charNum)):
            charNum+=10
            semicolonOffset=script[charNum:].index(';')
            openSquareOffset=script[charNum:].index('[')
            closeSquareOffset=script[charNum:].index(']')
            commaOffset=script[charNum:].index(',')
            syntacticallyCorrect=True
            for offset in [openSquareOffset,closeSquareOffset,commaOffset]:
                if((offset==-1) or (offset>semicolonOffset)):
                    print("Bifurcate command malformed, char:"+str(charNum))
                    syntacticallyCorrect=False
                    break
            if(syntacticallyCorrect):
                if(openSquareOffset==0):
                    leftHalf=script[charNum+openSquareOffset+1:charNum+commaOffset]
                    rightHalf=script[charNum+commaOffset+1:charNum+closeSquareOffset]
                    combinedName=script[charNum+closeSquareOffset+1:charNum+semicolonOffset]
                    ATHVars[combinedName]=bifurcate(ATHVars[leftHalf],ATHVars[rightHalf])
                else:
                    toSplitName=script[charNum:charNum+openSquareOffset]
                    leftHalf=script[charNum+openSquareOffset+1:charNum+commaOffset]
                    rightHalf=script[charNum+commaOffset+1:charNum+closeSquareOffset]
                    (ATHVars[leftHalf],ATHVars[rightHalf])=bifurcate(ATHVars[toSplitName])
        elif(re.match(r'([0-9a-zA-Z]+)\.DIE\(([0-9a-zA-Z]*)\);',script[charNum:])!=None):#script[charNum:script[charNum:].find(';')].endswith('.DIE()')):
            matches=re.match(r'([0-9a-zA-Z]+)\.DIE\(([0-9a-zA-Z]*)\);',script[charNum:])#.group(1)
            varname=matches.group(1)
            argvarname=matches.group(2)
            if argvarname:
                #print("argvarname is " +argvarname)
                return_obj=ATHVars[argvarname]
            #print "found .DIE(); statement! Variable name is "+varname
            ATHVars[varname].DIE()
            charNum=script.find(';',charNum)
            #print varname+"killed"
        elif(script.startswith('//',charNum)):
            nextNewlinePos=script.find('\n',charNum)
            if '\r' in script[charNum:nextNewlinePos]:
                nextNewlinePos=script.find('\r',charNum)
            charNum=nextNewlinePos
        elif(script.startswith('/*',charNum)):
            charNum=script.find('*/',charNum)
        elif(script.startswith('PYDEBUG',charNum)):
            pdb.set_trace()
            charNum+=5
        elif(re.match(r'([A-Z0-9_]+) \[([^\[\];]*),([^\[\];]*)\]([^\[\];]*);',script[charNum:])!=None):
            try:
                matches=re.match(r'([A-Z0-9_]+) \[([^\[\];]*),([^\[\];]*)\]([^\[\];]*);',script[charNum:])
                funName=matches.group(1)
                #print "the function called '"+funName + "' was called."
                #print "yeah it works."
                if funName in funCodes:
                    theFuncCode=funCodes[funName]
                    sentInObject=bifurcate(ATHVars[matches.group(2)],ATHVars[matches.group(3)])
                    ATHVars[matches.group(4)]=evalScript(theFuncCode,sentInObject)
                else:
                    print "error: function called '"+funName+"' not recognized"
                charNum+=len(funName)
            except:
                print "function not recognized/ a bug in the interpreter"
                print matches#re.match(r'([A-Z0-9_]+) \[([^\[\];]*),([^\[\];]*)\]([^\[\];]*);',script[charNum:])
                print "..."
                charNum+=1
            #charNum+=1
        elif(re.match(r'([A-Z0-9_]+) ([^\[\];]*)\[([^\[\];]*),([^\[\];]*)\];',script[charNum:])!=None):
            try:
                matches=re.match(r'([A-Z0-9_]+) ([^\[\];]*)\[([^\[\];]*),([^\[\];]*)\];',script[charNum:])
                funName=matches.group(1)
                #print "the function called '"+funName + "' was called."
                #print "yeah it works."
                if funName in funCodes:
                    theFuncCode=funCodes[funName]
                    sentInObject=ATHVars[matches.group(2)]#bifurcate(ATHVars[matches.group(2)],ATHVars[matches.group(3)])
                    ATHVars[matches.group(3)],ATHVars[matches.group(4)]=bifurcate(evalScript(theFuncCode,sentInObject))
                else:
                    print "error: function called '"+funName+"' not recognized"
                charNum+=len(funName)
            except:
                print "function not recognized/ a bug in the interpreter"
                print matches#re.match(r'([A-Z0-9_]+) \[([^\[\];]*),([^\[\];]*)\]([^\[\];]*);',script[charNum:])
                print "..."
                charNum+=1
        else:
             charNum+=1
             if(charNum > len(script)):
                 THIS.DIE()
        #print script[charNum]
    return return_obj
コード例 #6
0
ファイル: interp_2.py プロジェクト: Aquamace11/TILDE-ATH
BIFURCATE [BLAH,C]C;
}
/*
BIFURCATE [BLAH,C]CTEMP;
BIFURCATE CTEMP[JUNK,CTEMP];
~ATH(CTEMP){
BIFURCATE CTEMP[JUNK,CTEMP];
print some text;
}
print DONE!;
*/
THIS.DIE(C);
"""#NOTE:use a better addition algorithm.


NULL_obj=bif.value_obj()
NULL_obj.DIE()
def evalScript(script,inObj):
    ATHVars={}
    THIS=bif.value_obj()
    ATHVars['THIS']=THIS
    ATHVars['NULL']=NULL_obj
    ATHVars['ARGS']=inObj
    return_obj=NULL_obj

    charNum=0
    execStack=[]

    while(THIS.living):
        if(False):
            pass