def WHILE(inst): try: if inst[1] == 'PASS': return except IndexError: errors.valueError() if type(inst[0]) in [int, float]: if inst[0] > 0: while True: interp(inst[1:]) else: return elif type(inst[0]) == str and inst[0] not in gVars: if len(inst[0]) > 0: while True: interp(inst[1:]) else: return elif inst[0] in gVars: if type(gVars[inst[0]]) == str: while len(gVars[inst[0]]) > 0: interp(inst[1:]) elif type(gVars[inst[0]]) in [int, float]: while gVars[inst[0]] > 0: interp(inst[1:]) else: errors.syntaxError()
def IF(inst): if inst[0] == "TOP": arg = stack[-1] else: arg = inst[0] try: if inst[1] == 'PASS': return except IndexError: errors.valueError() if type(arg) in [int, float]: if arg > 0: interp(inst[1:]) else: return elif type(arg) == str and inst[0] not in gVars: if len(arg) > 0: interp(inst[1:]) else: return elif arg in gVars: if type(gVars[arg]) == str: if len(gVars[arg]) > 0: interp(inst[1:]) elif type(gVars[arg]) in [int, float]: if gVars[arg] > 0: interp(inst[1:]) else: return else: errors.valueError()
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()
def WIPE(): global stack if len(stack) < 1: errors.stackArgumentLenError("WIPE") else: if type(stack[-1]) != list: errors.valueError() else: del stack[-1][:]
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])
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])
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]
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")
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")
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")
def FOR(inst): if inst[0] == 'TOP': arg = stack[-1] else: arg = inst[0] try: if inst[1] == 'PASS': return except IndexError: errors.valueError() if type(arg) == int: for i in range(arg): interp(inst[1:]) elif type(gVars[arg]) != int: errors.valueError() else: for i in range(gVars[arg]): interp(inst[1:])
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()
def DEF(inst): global defs if inst[0] in dep.calls or inst[0] in dep.reserved or type(inst[0]) != str: errors.valueError() else: defs[inst[0]] = inst[1:]