Edit individual bytes of data
This commit is contained in:
37
src/main.py
37
src/main.py
@@ -1,9 +1,9 @@
|
||||
from email.charset import UNKNOWN8BIT
|
||||
import os
|
||||
import string
|
||||
import math as m
|
||||
from sys import argv
|
||||
file = open(argv[1]).readlines();
|
||||
bfcode = ""
|
||||
bfcode: str = ""
|
||||
variables = []
|
||||
varbytes = []
|
||||
braces = []
|
||||
@@ -21,26 +21,20 @@ def find_file(filename, root_dir):
|
||||
return os.path.join(dirpath, filename)
|
||||
return None
|
||||
|
||||
def removeChar(str, char):
|
||||
def removeChar(str: str, char: str) -> str:
|
||||
ans = ""
|
||||
for i in str:
|
||||
if (i != char):
|
||||
ans += i
|
||||
return ans
|
||||
|
||||
def removeEnd(string, num):
|
||||
def removeEnd(string: str) -> str:
|
||||
ans = ""
|
||||
for i in range(len(string)-1):
|
||||
ans += string[i]
|
||||
return ans
|
||||
|
||||
def ord2(char):
|
||||
if (len(char) == 1):
|
||||
return ord(char)
|
||||
elif (len(char == 0)):
|
||||
return(0)
|
||||
|
||||
def sign(num):
|
||||
def sign(num: float) -> int:
|
||||
if num < 0:
|
||||
return -1
|
||||
elif num == 0:
|
||||
@@ -64,7 +58,7 @@ for i in file:
|
||||
# Create command
|
||||
elif (i.split(" ")[0] == "create"):
|
||||
if (i[len(i)-1] == "\n"):
|
||||
i = removeEnd(i, 1)
|
||||
i = removeEnd(i)
|
||||
bfcode += ">>>>>>>>>>>>[[>>]>>]"
|
||||
|
||||
bytes = int(removeChar(i.split("*", 1)[1].split("=", 1)[0], " "))
|
||||
@@ -88,7 +82,7 @@ for i in file:
|
||||
|
||||
if (type == "string"):
|
||||
a = a.split("\"", 1)[1]
|
||||
a = removeEnd(a, 1)
|
||||
a = removeEnd(a)
|
||||
for j in range(bytes):
|
||||
bfcode += "+++>"
|
||||
if (j < len(a)):
|
||||
@@ -143,7 +137,7 @@ for i in file:
|
||||
elif (i.split(" ")[0] == "print"):
|
||||
a = i.split(" ", 1)[1]
|
||||
if a[len(a)-1] == "\n":
|
||||
a = removeEnd(a, 1)
|
||||
a = removeEnd(a)
|
||||
if (a in variables):
|
||||
bfcode += ">>>>>>>>>>>>"
|
||||
for j in range(variables.index(a)):
|
||||
@@ -194,7 +188,7 @@ for i in file:
|
||||
elif (i.split(" ")[0] == "set"):
|
||||
a = i.split(" ")[1]
|
||||
if a[len(a)-1] == "\n":
|
||||
a = removeEnd(a, 1)
|
||||
a = removeEnd(a)
|
||||
if (a in variables):
|
||||
bfcode += ">>>>>>>>>>>>"
|
||||
for j in range(variables.index(a)):
|
||||
@@ -207,10 +201,10 @@ for i in file:
|
||||
val = i.split("=", 1)[1].split(" ", 1)[1]
|
||||
type = None
|
||||
if (val[len(val)-1] == "\n"):
|
||||
val = removeEnd(val, 1)
|
||||
val = removeEnd(val)
|
||||
if (val[0] == "\"") & (val[len(val)-1] == "\""):
|
||||
val = val.split("\"", 1)[1]
|
||||
val = removeEnd(val, 1)
|
||||
val = removeEnd(val)
|
||||
type = "string"
|
||||
elif (val == "true") | (val == "false"):
|
||||
type = "bool"
|
||||
@@ -247,6 +241,15 @@ for i in file:
|
||||
else:
|
||||
raise TypeError("Could not find variable type")
|
||||
bfcode += "<<[[<<]<<]<<<<<<<<"
|
||||
elif "=" in i:
|
||||
if a.split("[")[0] in variables:
|
||||
var = a.split("[")[0]
|
||||
idx = int(a.split("[")[1].split("]")[0])
|
||||
bfcode += ">>>>>>>>>>>>" + "[>>]>>" * variables.index(var) + ">>" * idx + ">"
|
||||
bfcode += "[-]" + "+" * ord(i.split("=", 1)[1].split("\"")[1])
|
||||
bfcode += "<[[<<]<<]<<<<<<<<"
|
||||
else:
|
||||
raise NameError(f"Could not find variable {a.split("[")[0]}")
|
||||
else:
|
||||
raise NameError(f"Could not find variable {a}")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user