Ejemplo n.º 1
0
def MAX():
    """replaces top item of stack with largest of top 2"""
    global stack
    if len(stack) < 2:
        errors.stackArgumentLenError("MAX")
    else:
        stack = stack[:-2] + [max(stack[-2:])]
Ejemplo n.º 2
0
def NEG():
    """negate top item of stack"""
    global stack
    if len(stack) < 1:
        errors.stackArgumentLenError("NEGATE")
    else:
        stack[-1] = -stack[-1]
Ejemplo n.º 3
0
def DUP():
    """duplicates top item on stack"""
    global stack
    if len(stack) < 1:
        errors.stackArgumentLenError("DUP")
    else:
        stack.append(stack[-1])
Ejemplo n.º 4
0
def NIP():
    """deletes 2nd top item from stack"""
    global stack
    if len(stack) < 2:
        errors.stackArgumentLenError("NIP")
    else:
        del stack[-2]
Ejemplo n.º 5
0
def ABS():
    """get absolute value of top item on stack"""
    global stack
    if len(stack) < 1:
        errors.stackArgumentLenError("ABS")
    else:
        stack[-1] = abs(stack[-1])
Ejemplo n.º 6
0
def MIN():
    """replaces top item of stack with smallest of the top 2"""
    global stack
    if len(stack) < 2:
        errors.stackArgumentLenError("MIN")
    else:
        stack = stack[:-2] + [min(stack[-2:])]
Ejemplo n.º 7
0
def ROT():
    global stack
    if len(stack) < 3:
        errors.stackArgumentLenError("ROT")
    else:
        temp = stack[-3]
        del stack[-3]
        stack.append(temp)
Ejemplo n.º 8
0
def WIPE():
    global stack
    if len(stack) < 1:
        errors.stackArgumentLenError("WIPE")
    else:
        if type(stack[-1]) != list:
            errors.valueError()
        else:
            del stack[-1][:]
Ejemplo n.º 9
0
def ADD():
    global stack
    if len(stack) < 2:
        errors.stackArgumentLenError("ADD")
    else:
        if type(stack[-2]) != list:
            errors.valueError()
        else:
            stack[-2].insert(0, stack[-1])
Ejemplo n.º 10
0
def APPEND():
    global stack
    if len(stack) < 2:
        errors.stackArgumentLenError("APPEND")
    else:
        if type(stack[-2]) != list:
            errors.valueError()
        else:
            stack[-2].append(stack[-1])
Ejemplo n.º 11
0
def MULT():
    """Multiply top 2 items of stack"""
    global stack
    if len(stack) < 2:
        errors.stackArgumentLenError("MULTIPLY")
    else:
        temp = stack[-2] * stack[-1]
        stack = stack[:-2]
        stack.append(temp)
Ejemplo n.º 12
0
def MOD():
    """Perform modulus of top 2 items of stack"""
    global stack
    if len(stack) < 2:
        errors.stackArgumentLenError("MOD")
    else:
        temp = stack[-2] % stack[-1]
        stack = stack[:-2]
        stack.append(temp)
Ejemplo n.º 13
0
def LEN():
    global stack
    if len(stack) < 1:
        errors.stackArgumentLenError("LEN")
    else:
        if type(stack[-1]) in [str, list]:
            stack.append(len(stack[-1]))
        else:
            errors.valueError()
Ejemplo n.º 14
0
def MINUS():
    """Subtract top 2 items of stack"""
    global stack
    if len(stack) < 2:
        errors.stackArgumentLenError("MINUS")
    else:
        temp = stack[-2] - stack[-1]
        stack = stack[:-2]
        stack.append(temp)
Ejemplo n.º 15
0
def MORETHANEQ():
    global stack
    if len(stack) < 2:
        errors.stackArgumentLenError('MORETHANEQ')
    else:
        if stack[-2] >= stack[-1]:
            del stack[-2:]
            stack.append(1)
        else:
            del stack[-2:]
            stack.append(0)
Ejemplo n.º 16
0
def LESSTHAN():
    global stack
    if len(stack) < 2:
        errors.stackArgumentLenError('LESSTHAN')
    else:
        if stack[-2] < stack[-1]:
            del stack[-2:]
            stack.append(1)
        else:
            del stack[-2:]
            stack.append(0)
Ejemplo n.º 17
0
def NOTEQUALS():
    global stack
    if len(stack) < 2:
        errors.stackArgumentLenError('EQUALS')
    else:
        if stack[-2] != stack[-1]:
            del stack[-2:]
            stack.append(1)
        else:
            del stack[-2:]
            stack.append(0)
Ejemplo n.º 18
0
def DIV():
    """Divide top 2 items of stack"""
    global stack
    if len(stack) < 2:
        errors.stackArgumentLenError("DIVIDE")
    else:
        temp = float(stack[-2]) / float(stack[-1])
        stack = stack[:-2]
        if str(temp)[-2:] == '.0':
            stack.append(int(temp))
        else:
            stack.append(temp)
Ejemplo n.º 19
0
def DROP():
    global stack
    if len(stack) < 1:
        errors.stackArgumentLenError("DROP")
    else:
        if type(stack[-1]) != list:
            errors.valueError()
        else:
            if len(stack[-1]) < 1:
                errors.indexError("DROP from empty list")
            else:
                del stack[-1][-1]
Ejemplo n.º 20
0
def PLUS():
    """Add top 2 items of stack"""
    global stack
    if len(stack) < 2:
        errors.stackArgumentLenError("PLUS")
    else:
        try:
            temp = stack[-1] + stack[-2]
        except TypeError:
            errors.opError()
        stack = stack[:-2]
        stack.append(temp)
Ejemplo n.º 21
0
def GET(index):
    global stack
    if index in dep.globalVs:
        index = dep.globalVs[index]
    if len(stack) < 1:
        errors.stackArgumentLenError("GET")
    else:
        if type(stack[-1]) not in [list, str]:
            errors.valueError()
        else:
            try:
                stack.append(stack[-1][index])
            except IndexError:
                errors.indexError("index out of range")
Ejemplo n.º 22
0
def DEL(index):
    global stack
    if index in dep.globalVs:
        index = dep.globalVs[index]
    if len(stack) < 1:
        errors.stackArgumentLenError("DEL")
    else:
        if type(stack[-1]) != list:
            errors.valueError()
        else:
            try:
                del stack[-1][index]
            except IndexError:
                errors.indexError("Array index out of range")
Ejemplo n.º 23
0
def INSERT(index):
    global stack
    if index in dep.globalVs:
        index = dep.globalVs[index]
    if len(stack) < 2:
        errors.stackArgumentLenError("INSERT")
    else:
        if type(stack[-2]) != list:
            errors.valueError()
        else:
            try:
                stack[-2][index] = stack[-1]
            except IndexError:
                errors.indexError("Array index out of range")
Ejemplo n.º 24
0
def NOT():
    global stack
    if len(stack) < 1:
        errors.stackArgumentLenError('NOT')
    else:
        if type(stack[-1]) == str:
            if len(stack[-1]) > 0:
                del stack[-1]
                stack.append(0)
            else:
                del stack[-1]
                stack.append(1)
        elif type(stack[-1]) in [int, float]:
            if stack[-1] > 0:
                del stack[-1]
                stack.append(0)
            else:
                del stack[-1]
                stack.append(1)
Ejemplo n.º 25
0
def OR():
    global stack
    if len(stack) < 2:
        errors.stackArgumentLenError('OR')
    else:
        if type(stack[-1]) == type(stack[-2]) == int or type(
                stack[-1]) == type(stack[-2]) == float:
            if stack[-1] > 0 or stack[-2] > 0:
                del stack[-2:]
                stack.append(1)
            else:
                del stack[-2:]
                stack.append(0)
        elif type(stack[-1]) == type(stack[-2]) == str:
            if len(stack[-1]) > 0 or len(stack[-2]) > 0:
                del stack[-2:]
                stack.append(1)
            else:
                del stack[-2:]
                stack.append(0)
        else:
            errors.valueError()
Ejemplo n.º 26
0
def CMD():
    if len(stack) < 1:
        errors.stackArgumentLenError('CMD')
    else:
        os.system(stack[-1])
Ejemplo n.º 27
0
def TRIM():
    global stack
    if len(stack) < 1:
        errors.stackArgumentLenError("TRIM")
    else:
        del stack[0]