Print function and readme.md
This commit is contained in:
@@ -1,3 +1,9 @@
|
|||||||
## create var = Value
|
## create var *bytes = Value
|
||||||
|
|
||||||
Creates the variable "var" and initialises its value.
|
Creates the variable "var" with a set number of bytes allocated to it, and initialises its value.
|
||||||
|
|
||||||
|
Example: `create var *5 = "Hello"`
|
||||||
|
|
||||||
|
## print var
|
||||||
|
|
||||||
|
Prints the value of `var` to the console, where `var` is a variable.
|
16
readme.md
16
readme.md
@@ -1,3 +1,17 @@
|
|||||||
## Welcome to BrainAssembly!
|
## 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!
|
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!
|
||||||
|
|
||||||
|
To run:
|
||||||
|
|
||||||
|
- First clone this repository and install python.
|
||||||
|
```
|
||||||
|
git clone https://chookspace.com/DiamondNether90/BrainAssembly
|
||||||
|
```
|
||||||
|
|
||||||
|
- Next, run the following command to compile a .basm file to Brainfuck:
|
||||||
|
```
|
||||||
|
python3 src/main.py path/to/file.basm path/to/file.bf
|
||||||
|
```
|
||||||
|
|
||||||
|
This will create or replace the contents of path/to/file.bf with the compiled BrainAssembly code.
|
21
src/main.py
21
src/main.py
@@ -2,6 +2,7 @@ import string
|
|||||||
from sys import argv
|
from sys import argv
|
||||||
file = open(argv[1]).readlines();
|
file = open(argv[1]).readlines();
|
||||||
bfcode = ""
|
bfcode = ""
|
||||||
|
variables = []
|
||||||
def removeChar(str, char):
|
def removeChar(str, char):
|
||||||
ans = ""
|
ans = ""
|
||||||
for i in str:
|
for i in str:
|
||||||
@@ -47,9 +48,23 @@ for i in file:
|
|||||||
if (j < len(a)):
|
if (j < len(a)):
|
||||||
bfcode += "+" * ord(a[j]) + ">"
|
bfcode += "+" * ord(a[j]) + ">"
|
||||||
bfcode += "<[[<<]<<]<<<<<<<<<"
|
bfcode += "<[[<<]<<]<<<<<<<<<"
|
||||||
print(type)
|
|
||||||
else:
|
variables.append(i.split(" ")[1].split("*")[0])
|
||||||
print("what the sigma")
|
|
||||||
|
elif (i.split(" ")[0] == "print"):
|
||||||
|
a = i.split(" ", 1)[1]
|
||||||
|
if a[len(a)-1] == "\n":
|
||||||
|
a = removeEnd(a, 1)
|
||||||
|
if (a in variables):
|
||||||
|
bfcode += ">>>>>>>>>>>>"
|
||||||
|
for i in range(variables.index(a)):
|
||||||
|
bfcode += "[>>]>>"
|
||||||
|
bfcode += "[>.>]<<[[<<]<<]<<<<<<<<++++++++++.[-]"
|
||||||
|
else:
|
||||||
|
raise NameError(f"Could not find variable {a}")
|
||||||
|
|
||||||
|
elif ((i != "\n") & (i != "")):
|
||||||
|
raise ValueError(f"Invalid Command")
|
||||||
|
|
||||||
with open(argv[2], "w") as file:
|
with open(argv[2], "w") as file:
|
||||||
file.write(bfcode)
|
file.write(bfcode)
|
@@ -1,3 +1,7 @@
|
|||||||
create str *5 = "Hello, world!"
|
create hello *5 = "Hello, world!"
|
||||||
create str *5 = "World, hello!"
|
create world *5 = "World, hello!"
|
||||||
create str *6 = "Sigma!"
|
create sigma *6 = "Sigma!"
|
||||||
|
|
||||||
|
print hello
|
||||||
|
print world
|
||||||
|
print sigma
|
@@ -0,0 +1 @@
|
|||||||
|
>>>>>>>>>>>>[[>>]>>]+++>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>+++>+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>+++>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>+++>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>+++>+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++><[[<<]<<]<<<<<<<<<>>>>>>>>>>>>[[>>]>>]+++>+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>+++>+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>+++>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>+++>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>+++>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++><[[<<]<<]<<<<<<<<<>>>>>>>>>>>>[[>>]>>]+++>+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>+++>+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>+++>+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>+++>+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>+++>+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>+++>+++++++++++++++++++++++++++++++++><[[<<]<<]<<<<<<<<<>>>>>>>>>>>>[>.>]<<[[<<]<<]<<<<<<<<++++++++++.[-]>>>>>>>>>>>>[>>]>>[>.>]<<[[<<]<<]<<<<<<<<++++++++++.[-]>>>>>>>>>>>>[>>]>>[>>]>>[>.>]<<[[<<]<<]<<<<<<<<++++++++++.[-]
|
Reference in New Issue
Block a user