-
Notifications
You must be signed in to change notification settings - Fork 0
/
code_to_python.py
30 lines (26 loc) · 914 Bytes
/
code_to_python.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# code_to_python.py
import re
def convert_line(line):
if line.startswith("memory"):
return line.replace(" = ", " = \"") + "\""
elif line.startswith("def"):
return "def " + line[4:]
elif line.startswith("for"):
return " for " + line[4:]
elif line.startswith("return"):
return " return " + line[7:]
else:
return None
def code_to_python(input_file, output_file):
with open(input_file, "r") as code_file, open(output_file, "w") as py_file:
for line in code_file:
if line.startswith("#"):
py_file.write(line)
else:
converted_line = convert_line(line.strip())
if converted_line:
py_file.write(converted_line + "\n")
if __name__ == "__main__":
input_file = "brain.CODE"
output_file = "brain.py"
code_to_python(input_file, output_file)