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