diff --git a/src/main.py b/src/main.py index 9d05d4b..390c5fa 100644 --- a/src/main.py +++ b/src/main.py @@ -241,12 +241,34 @@ 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 += "+" * int(removeChar(i.split("+=")[1], " ")) + bfcode += "<[[<<]<<]<<<<<<<<" + else: + raise NameError(f"Could not find variable {a.split("[")[0]}") + 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 += "-" * int(removeChar(i.split("-=")[1], " ")) + bfcode += "<[[<<]<<]<<<<<<<<" + else: + raise NameError(f"Could not find variable {a.split("[")[0]}") 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]) + if "\"" in i: + replace = ord(i.split("=", 1)[1].split("\"")[1]) + else: + replace = int(i.split("=", 1)[1].lstrip().rstrip()) + bfcode += "[-]" + "+" * replace bfcode += "<[[<<]<<]<<<<<<<<" else: raise NameError(f"Could not find variable {a.split("[")[0]}") diff --git a/tests/create.basm b/tests/create.basm index 31d6e3e..9a2f1fd 100644 --- a/tests/create.basm +++ b/tests/create.basm @@ -1,4 +1,4 @@ create var *5 = "Hello" create var2 *5 = "World" set var[1] = "E" -set var2[2] = "R" \ No newline at end of file +set var2[2] -= 1 \ No newline at end of file