Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # This interpreter is not yet tested.
- # It should work, but I can't be 100% sure.
- log = []
- charlog = []
- depth = 0
- next = ""
- code = ""
- line = 1
- char = 0
- tempcmd = ""
- cmd = ""
- loc = [3,2]
- hand = None
- factoryStorage = [
- [0,1,2,10,None],
- [None,None,None,None,None],
- [None,None,None,None,None],
- [None,None,1,None,None],]
- factorymap = [
- ["0","1","2","T","%"],
- ["-","S","P","Q","*"],
- ["+","#","@","C","&"],
- ["=","/","X","!","~"],]
- S=[]
- P=[]
- from queue import *
- Q=Queue()
- def Supply(number):
- global hand
- if hand==None:
- hand=number
- else:
- hand=None
- def PickDrop(X,Y):
- global hand
- if hand==None:
- hand=factoryStorage[X][Y]
- factoryStorage[X][Y]=None
- else:
- factoryStorage[X][Y]=hand
- hand=None
- def Math(X,Y,mod=1):
- global hand
- global factoryStorage
- if hand==None:
- hand=factoryStorage[X][Y]
- factoryStorage[X][Y]=None
- elif factoryStorage[X][Y]==None:
- factoryStorage[X][Y]=hand
- hand=None
- else:
- factoryStorage[X][Y]+=(hand*mod)
- hand=None
- def StackRoom(stack):
- global hand
- if hand==None:
- if len(stack)!=0:
- hand=stack.pop
- else:
- stack.append(hand)
- hand=None
- def QueueRoom(queue):
- global hand
- if hand==None:
- if not queue.empty:
- hand=queue.get
- else:
- queue.put(hand)
- hand=None
- def OutputInt():
- global hand
- if hand!=None:
- print(hand,end=" ",flush=True)
- hand=None
- def OutputLetter():
- global hand
- if hand!=None:
- if hand in Letters:
- print(Letters[hand],end=" ",flush=True)
- hand=None
- def Burn():
- global hand
- hand=None
- def Compare(X,Y,invert=False):
- global hand
- global factoryStorage
- result=0
- if hand==None:
- hand=factoryStorage[X][Y]
- factoryStorage[X][Y]=None
- elif factoryStorage[X][Y]==None:
- factoryStorage[X][Y]=hand
- hand=None
- elif factoryStorage[X][Y]==hand:
- hand=None
- factoryStorage[X][Y]=None
- result=1
- else:
- hand=None
- factoryStorage[X][Y]=None
- result=0
- if invert==True and result==1:
- result=0
- elif invert==True and result==0:
- result=1
- factoryStorage[3][2]=result
- def Invert(X,Y):
- global hand
- if hand==None:
- hand=factoryStorage[X][Y]
- factoryStorage[X][Y]=None
- elif hand==0:
- factoryStorage[X][Y]=1
- hand=None
- else:
- factoryStorage[X][Y]=0
- hand=None
- def Copy(X,Y,CX,CY):
- global hand
- if hand==None:
- hand=factoryStorage[X][Y]
- factoryStorage[X][Y]=None
- else:
- factoryStorage[X][Y]=hand
- factoryStorage[CX][CY]=hand
- hand=None
- def Input(X,Y):
- hold=input("\n> ")
- hold=int(hold)
- factoryStorage[X][Y]=hold
- Letters = {
- 0: " ",
- 1: "A",
- 2: "B",
- 3: "C",
- 4: "D",
- 5: "E",
- 6: "F",
- 7: "G",
- 8: "H",
- 9: "I",
- 10: "J",
- 11: "K",
- 12: "L",
- 13: "M",
- 14: "N",
- 15: "O",
- 16: "P",
- 17: "Q",
- 18: "R",
- 19: "S",
- 20: "T",
- 21: "U",
- 22: "V",
- 23: "W",
- 24: "X",
- 25: "Y",
- 26: "Z",
- 27: "\n"}
- import linecache
- import os
- A = os.getcwd()
- print('Choose a Number Factory program file in: ' + A)
- code = input("File name: ")
- code = A+"/"+code
- print(code)
- while 1 == 1:
- tempcmd = linecache.getline(code, line)
- if len(cmd)!=0:
- cmd = tempcmd[char]
- if depth == 0:
- if cmd == '>':
- loc[1]+=1
- if loc==[0,4]:
- Input(0,4)
- if cmd == '<':
- loc[1]-=1
- if loc==[0,4]:
- Input(0,4)
- if cmd == '^':
- loc[0]-=1
- if loc==[0,4]:
- Input(0,4)
- if cmd == 'V':
- loc[0]+=1
- if loc==[0,4]:
- Input(0,4)
- if cmd == '%':
- room=factorymap[loc[0]][loc[1]]
- if room=="0":
- Supply(0)
- elif room=="1":
- Supply(1)
- elif room=="2":
- Supply(2)
- elif room=="T":
- Supply(10)
- elif room=="%":
- PickDrop(0,4)
- elif room=="-":
- Math(1,0,-1)
- elif room=="S":
- StackRoom(S)
- elif room=="P":
- StackRoom(P)
- elif room=="Q":
- QueueRoom(Q)
- elif room=="*":
- OutputInt()
- elif room=="+":
- Math(2,0,1)
- elif room=="#":
- Copy(2,1,2,3)
- elif room=="@":
- PickDrop(2,2)
- elif room=="C":
- PickDrop(2,3)
- elif room=="&":
- Burn()
- elif room=="=":
- Compare(3,0,False)
- elif room=="/":
- Compare(3,1,True)
- elif room=="X":
- PickDrop(3,2)
- elif room=="!":
- Invert(3,3)
- elif room=="~":
- OutputLetter()
- if cmd == '':
- break
- if cmd == '(':
- if factoryStorage[3][2] == 0:
- depth=depth+1
- else:
- log.append(line)
- charlog.append(char)
- if cmd == ')':
- if factoryStorage[3][2] != 0:
- line = log[-1]
- char = charlog[-1]
- else:
- log.pop
- charlog.pop
- else:
- if cmd == '(':
- depth+=1
- if cmd == ')':
- depth-=1
- if cmd == '':
- depth=0
- break
- next = tempcmd[char+1]
- if next == ' ' or next == '\n':
- char=0
- line = line + 1
- else:
- char=char+1
- print('End of program.')
- linecache.clearcache()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement