Advertisement
LazerAio

AsmLBfHelper.py

Dec 9th, 2022 (edited)
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.21 KB | None | 0 0
  1. #This script converts a madeup assembely like language into brainfuck language
  2. #The madeup language has the following commands:
  3. #Def - Define a variable - St,B+,Sw
  4. #Add n v - Add n to veriable - St,B+,Sw
  5. #Sub n v - Sub n from veriable - St,B+,Sw
  6. #Prn s - Print a string - St,B+
  7. #Var v - Print a variable - B+,Sw
  8. #Loop  - Start a loop - St,B+,Sw
  9. #End   - End current loop - St,B+,Sw
  10. #Halt  - Stop the script - B+
  11. #St - brainfuck standard
  12. #B+ - brainfuck plus
  13. #Sw - brainfuck for stormworks
  14.  
  15. #Define the script here!
  16. Script = [
  17. "Prn H", "Prn E", "Prn L", "Prn L", "Prn O", "Prn !", "Prn !"
  18. ]
  19. #The following is the actual script
  20. Output = []
  21. Veriables = []
  22. CurrCell = 0
  23. print("Cell | Allocation")
  24. for i in range(len(Script)):
  25.     if Script[i][0] == "D":
  26.         Veriables.append(0)
  27.         print(len(Veriables),end=' ')
  28.         print("Veriable")
  29. Veriables.append(0)
  30. print(len(Veriables),"Variable",len(Veriables))
  31. Veriables.append(0)
  32. print(len(Veriables),"Buffer",len(Veriables))
  33. Veriables.append(0)
  34. print(len(Veriables),"Padding")
  35. print(len(Veriables)+1,"Printing")
  36. for i in range(len(Script)):
  37.     if Script[i][0] == "A":
  38.         for j in range(int(Script[i][6])):
  39.             if CurrCell > int(Script[i][6]):
  40.                 Output.append("<")
  41.                 CurrCell = CurrCell - 1
  42.             elif CurrCell < int(Script[i][6]):
  43.                 Output.append(">")
  44.                 CurrCell = CurrCell + 1
  45.         for j in range(int(Script[i][4])):
  46.             Veriables[int(Script[i][6])] =+ 1
  47.             Output.append("+")
  48.     elif Script[i][0] == "S":
  49.         for j in range(int(Script[i][6])):
  50.             if CurrCell > int(Script[i][6]):
  51.                 Output.append("<")
  52.                 CurrCell = CurrCell - 1
  53.             elif CurrCell < int(Script[i][6]):
  54.                 Output.append(">")
  55.                 CurrCell = CurrCell + 1
  56.         for j in range(int(Script[i][4])):
  57.             Veriables[int(Script[i][6])] =- 1
  58.             Output.append("-")
  59.     elif Script[i][0] == "P":
  60.         if CurrCell > len(Veriables)+1:
  61.             Output.append("<")
  62.             CurrCell = CurrCell - 1
  63.         elif CurrCell < len(Veriables)+1:
  64.             Output.append(">")
  65.             CurrCell = CurrCell + 1
  66.         Output.append("[")
  67.         Output.append("-")
  68.         Output.append("]")
  69.         for j in range(ord(Script[i][4])):
  70.             Output.append("+")
  71.         Output.append(".")
  72.     elif Script[i][0] == "V":
  73.         if CurrCell > len(Veriables)+1:
  74.             Output.append("<")
  75.             CurrCell = CurrCell - 1
  76.         elif CurrCell < len(Veriables)+1:
  77.             Output.append(">")
  78.             CurrCell = CurrCell + 1
  79.         Output.append("[")
  80.         Output.append("-")
  81.         Output.append("]")
  82.         for j in range(int(Veriables[int(Script[i][4])])):
  83.             Output.append("+")
  84.         Output.append(".")
  85.     elif Script[i][0] == "L":
  86.         Output.append("[")
  87.     elif Script[i][0] == "E":
  88.         Output.append("]")
  89.     elif Script[i][0] == "H":
  90.         Output.append("!")
  91. print("----------------------------------------------------------------")
  92. print("Input code:")
  93. print(Script)
  94. print("Output code:")
  95. for i in range(len(Output)):
  96.     print(Output[i],end='')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement