Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #This script converts a madeup assembely like language into brainfuck language
- #The madeup language has the following commands:
- #Def - Define a variable - St,B+,Sw
- #Add n v - Add n to veriable - St,B+,Sw
- #Sub n v - Sub n from veriable - St,B+,Sw
- #Prn s - Print a string - St,B+
- #Var v - Print a variable - B+,Sw
- #Loop - Start a loop - St,B+,Sw
- #End - End current loop - St,B+,Sw
- #Halt - Stop the script - B+
- #St - brainfuck standard
- #B+ - brainfuck plus
- #Sw - brainfuck for stormworks
- #Define the script here!
- Script = [
- "Prn H", "Prn E", "Prn L", "Prn L", "Prn O", "Prn !", "Prn !"
- ]
- #The following is the actual script
- Output = []
- Veriables = []
- CurrCell = 0
- print("Cell | Allocation")
- for i in range(len(Script)):
- if Script[i][0] == "D":
- Veriables.append(0)
- print(len(Veriables),end=' ')
- print("Veriable")
- Veriables.append(0)
- print(len(Veriables),"Variable",len(Veriables))
- Veriables.append(0)
- print(len(Veriables),"Buffer",len(Veriables))
- Veriables.append(0)
- print(len(Veriables),"Padding")
- print(len(Veriables)+1,"Printing")
- for i in range(len(Script)):
- if Script[i][0] == "A":
- for j in range(int(Script[i][6])):
- if CurrCell > int(Script[i][6]):
- Output.append("<")
- CurrCell = CurrCell - 1
- elif CurrCell < int(Script[i][6]):
- Output.append(">")
- CurrCell = CurrCell + 1
- for j in range(int(Script[i][4])):
- Veriables[int(Script[i][6])] =+ 1
- Output.append("+")
- elif Script[i][0] == "S":
- for j in range(int(Script[i][6])):
- if CurrCell > int(Script[i][6]):
- Output.append("<")
- CurrCell = CurrCell - 1
- elif CurrCell < int(Script[i][6]):
- Output.append(">")
- CurrCell = CurrCell + 1
- for j in range(int(Script[i][4])):
- Veriables[int(Script[i][6])] =- 1
- Output.append("-")
- elif Script[i][0] == "P":
- if CurrCell > len(Veriables)+1:
- Output.append("<")
- CurrCell = CurrCell - 1
- elif CurrCell < len(Veriables)+1:
- Output.append(">")
- CurrCell = CurrCell + 1
- Output.append("[")
- Output.append("-")
- Output.append("]")
- for j in range(ord(Script[i][4])):
- Output.append("+")
- Output.append(".")
- elif Script[i][0] == "V":
- if CurrCell > len(Veriables)+1:
- Output.append("<")
- CurrCell = CurrCell - 1
- elif CurrCell < len(Veriables)+1:
- Output.append(">")
- CurrCell = CurrCell + 1
- Output.append("[")
- Output.append("-")
- Output.append("]")
- for j in range(int(Veriables[int(Script[i][4])])):
- Output.append("+")
- Output.append(".")
- elif Script[i][0] == "L":
- Output.append("[")
- elif Script[i][0] == "E":
- Output.append("]")
- elif Script[i][0] == "H":
- Output.append("!")
- print("----------------------------------------------------------------")
- print("Input code:")
- print(Script)
- print("Output code:")
- for i in range(len(Output)):
- print(Output[i],end='')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement