Reassign variables with set, bugfixes for strings shorter than allocated size
This commit is contained in:
40
src/main.py
40
src/main.py
@@ -3,6 +3,7 @@ from sys import argv
|
||||
file = open(argv[1]).readlines();
|
||||
bfcode = ""
|
||||
variables = []
|
||||
varbytes = []
|
||||
def removeChar(str, char):
|
||||
ans = ""
|
||||
for i in str:
|
||||
@@ -29,6 +30,7 @@ for i in file:
|
||||
bfcode += ">>>>>>>>>>>>[[>>]>>]"
|
||||
|
||||
bytes = int(removeChar(i.split("*", 1)[1].split("=", 1)[0], " "))
|
||||
varbytes.append(bytes)
|
||||
|
||||
a = i.split("=", 1)[1]
|
||||
if (a[0] == " "):
|
||||
@@ -47,7 +49,9 @@ for i in file:
|
||||
bfcode += "+++>"
|
||||
if (j < len(a)):
|
||||
bfcode += "+" * ord(a[j]) + ">"
|
||||
bfcode += "<[[<<]<<]<<<<<<<<<"
|
||||
else:
|
||||
bfcode += ">"
|
||||
bfcode += "<<[[<<]<<]<<<<<<<<"
|
||||
|
||||
variables.append(i.split(" ")[1].split("*")[0])
|
||||
|
||||
@@ -57,11 +61,43 @@ for i in file:
|
||||
a = removeEnd(a, 1)
|
||||
if (a in variables):
|
||||
bfcode += ">>>>>>>>>>>>"
|
||||
for i in range(variables.index(a)):
|
||||
for j in range(variables.index(a)):
|
||||
bfcode += "[>>]>>"
|
||||
bfcode += "[>.>]<<[[<<]<<]<<<<<<<<++++++++++.[-]"
|
||||
else:
|
||||
raise NameError(f"Could not find variable {a}")
|
||||
|
||||
elif (i.split(" ")[0] == "set"):
|
||||
a = i.split(" ")[1]
|
||||
if a[len(a)-1] == "\n":
|
||||
a = removeEnd(a, 1)
|
||||
if (a in variables):
|
||||
bfcode += ">>>>>>>>>>>>"
|
||||
for j in range(variables.index(a)):
|
||||
bfcode += "[>>]>>"
|
||||
for j in range(varbytes[variables.index(a)]):
|
||||
bfcode += "[-]>[-]>"
|
||||
for j in range(varbytes[variables.index(a)]):
|
||||
bfcode += "<<"
|
||||
# Get type
|
||||
val = i.split("=", 1)[1].split(" ", 1)[1]
|
||||
if (val[len(val)-1] == "\n"):
|
||||
val = removeEnd(val, 1)
|
||||
if (val[0] == "\"") & (val[len(val)-1] == "\""):
|
||||
val = val.split("\"", 1)[1]
|
||||
val = removeEnd(val, 1)
|
||||
type = "string"
|
||||
|
||||
if (type == "string"):
|
||||
for j in range(varbytes[variables.index(a)]):
|
||||
bfcode += "+++>"
|
||||
if (j >= len(val)):
|
||||
bfcode += ">"
|
||||
else:
|
||||
bfcode += "+" * ord(val[j]) + ">"
|
||||
bfcode += "<<[[<<]<<]<<<<<<<<"
|
||||
else:
|
||||
raise NameError(f"Could not find variable {a}")
|
||||
|
||||
elif ((i != "\n") & (i != "")):
|
||||
raise ValueError(f"Invalid Command")
|
||||
|
||||
Reference in New Issue
Block a user