Example Interpreter

Run Settings
LanguagePython
Language Version
Run Command
### import sys ### prg = [x for x in open(sys.argv[1], "r").read().replace("\n", " ").split(" ") if x != ""] prg = [x for x in open("prg", "r").read().replace("\n", " ").split(" ") if x != ""] env = {} pc = 0 stk = [] while prg[pc] != "halt": if prg[pc] == "{": while prg[pc] != "}": pc += 1 elif prg[pc] == "push":stk.append(prg[pc+1]);pc += 1 elif prg[pc] == "pop":stk.pop() elif prg[pc] == "rev":stk = stk[::-1] elif prg[pc] == "dup":t = stk.pop();stk.append(t);stk.append(t) elif prg[pc] == "store":env[prg[pc+1]] = stk.pop();pc += 1 elif prg[pc] == "load":stk.append(env[prg[pc+1]]);pc += 1 elif prg[pc] == "cast": if prg[pc+1] == "int":stk.append(int(stk.pop())) elif prg[pc+1] == "str":stk.append(str(stk.pop())) elif prg[pc+1] == "float":stk.append(float(stk.pop())) elif prg[pc+1] == "bool":stk.append(bool(stk.pop())) elif prg[pc] == "add":stk.append(stk.pop() + stk.pop()) elif prg[pc] == "sub":stk.append(stk.pop() - stk.pop()) elif prg[pc] == "div":stk.append(stk.pop() / stk.pop()) elif prg[pc] == "mul":stk.append(stk.pop() * stk.pop()) elif prg[pc] == "xor":stk.append(stk.pop() ^ stk.pop()) elif prg[pc] == "and":stk.append(stk.pop() & stk.pop()) elif prg[pc] == "or":stk.append(stk.pop() | stk.pop()) elif prg[pc] == "inv":stk.append(~stk.pop()) elif prg[pc] == "bnv":stk.append(not stk.pop()) elif prg[pc] == "chr":stk.append(chr(stk.pop())) elif prg[pc] == "ord":stk.append(ord(stk.pop())) elif prg[pc] == "equ":stk.append(stk.pop() == stk.pop()) elif prg[pc] == "jmp":pc = stk.pop() elif prg[pc] == "jnz": if stk.pop() != False or 0:pc = stk.pop() elif prg[pc] == "jz": if stk.pop() == False or 0:pc = stk.pop() elif prg[pc] == "out": print(stk.pop(), end='') elif prg[pc] == "inp": stk.append(input()) pc += 1
push Hello push 32 { character code for a space } cast int chr push World! rev { Reverse the stack, otherwise it would come out as 'World! Hello' } add { String Concatenation } add out halt
Editor Settings
Theme
Key bindings
Full width
Lines