commit 8cc737962efea515cb8fbab9e3efa4b3c0c5807c Author: DiamondNether90 Date: Mon Oct 6 10:50:14 2025 +1100 Create Command diff --git a/docs/syntax.md b/docs/syntax.md new file mode 100644 index 0000000..51ab6e7 --- /dev/null +++ b/docs/syntax.md @@ -0,0 +1,3 @@ +## create var = Value + +Creates the variable "var" and initialises its value. \ No newline at end of file diff --git a/readme.md b/readme.md new file mode 100644 index 0000000..aaf8bbd --- /dev/null +++ b/readme.md @@ -0,0 +1,3 @@ +## Welcome to BrainAssembly! + +BrainAssembly is a language that compiles to Brainfuck. Similar to Assembly languages, it has simple syntax, and is designed to make Brainfuck easier to write code for. Enjoy! \ No newline at end of file diff --git a/src/main.py b/src/main.py new file mode 100644 index 0000000..0b84ae4 --- /dev/null +++ b/src/main.py @@ -0,0 +1,54 @@ +import string +from sys import argv +file = open(argv[1]).readlines(); +bfcode = "" +def removeChar(str, char): + ans = 0 + for i in str: + if (i != char): + ans += i + return ans + +def removeEnd(string, num): + 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) + +for i in file: + if (i.split(" ")[0] == "create"): + i = removeEnd(i, 2) + bfcode += ">>>>>>>>>>>>[[>>]>>]" + + bytes = int(i.split("*", 1)[1].split("=", 1)[0]) + + a = i.split("=", 1)[1] + if (a[0] == " "): + a = a.split(" ", 1)[1] + + # Get type + if ((a[0] == "\"") & (a[len(a)-1] == "\"")): + type = "string" + else: + type = "undefined" + + if (type == "string"): + a = a.split("\"", 1)[1] + a = removeEnd(a, 1) + for j in range(bytes): + bfcode += "+++>" + if (j < len(a)): + bfcode += "+" * ord(a[j]) + ">" + bfcode += "<[[<<]<<]<<<<<<<<<" + print(type) + else: + print("what the sigma") + +with open(argv[2], "w") as file: + file.write(bfcode) \ No newline at end of file diff --git a/tests/main.basm b/tests/main.basm new file mode 100644 index 0000000..58df710 --- /dev/null +++ b/tests/main.basm @@ -0,0 +1,3 @@ +create str *5= "Hello, world!" +create str *5= "World, hello!" +create str *6= "Sigma!" diff --git a/tests/main.bf b/tests/main.bf new file mode 100644 index 0000000..7e66c8b --- /dev/null +++ b/tests/main.bf @@ -0,0 +1 @@ +>>>>>>>>>>>>[[>>]>>]+++>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>+++>+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>+++>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>+++>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>+++>+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++><[[<<]<<]<<<<<<<<<>>>>>>>>>>>>[[>>]>>]+++>+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>+++>+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>+++>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>+++>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>+++>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++><[[<<]<<]<<<<<<<<<>>>>>>>>>>>>[[>>]>>]+++>+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>+++>+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>+++>+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>+++>+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>+++>+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>+++>+++++++++++++++++++++++++++++++++><[[<<]<<]<<<<<<<<< \ No newline at end of file