Advertisement
Ractangle

TESTLANG interpreter

Nov 30th, 2024 (edited)
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.64 KB | None | 0 0
  1. i=input(">>").split()
  2. cmd=0;s=[];inp='';o=[]
  3. while len(i)!=0:
  4.  cmd+=1
  5.  if i[0]=="out":
  6.   if i[1]=="char":
  7.    o.append(chr(int(i.pop(2))))
  8.    i.pop(0);i.pop(0)
  9.   else:o.append(i.pop(1));i.pop(0)
  10.  elif i[0]=="note":i.pop(0);i.pop(0)
  11.  elif i[0]=="in":inp=input("input\n");i.pop(0)
  12.  elif i[0]=="push":
  13.   if i[1]=="in":s.append(inp);i.pop(0);i.pop(0)
  14.   elif i[1]=="out":o.append(s.pop(0));i.pop(0);i.pop(0)
  15.   else:s.append(i.pop(1));i.pop(0)
  16.  elif i[0]=="op":
  17.   if i[1]=="plus":
  18.    s.append(str(int(s.pop(0))+int(s.pop(0))))
  19.    i.pop(0);i.pop(0)
  20.   elif i[0]=="end":print("".join(o));break
  21.   else:print(f"CMD:{cmd} UNDEFINED COMMAND");break
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement