This is a test.

This commit is contained in:
KikooDX 2020-05-05 19:08:02 +02:00
parent 983a18d68c
commit 7878230778
5 changed files with 78 additions and 0 deletions

10
MAIN.txt Normal file
View File

@ -0,0 +1,10 @@
List 1 = {5, 6, 7}
B = 0
For A = 1 To 5 Step 2
Locate A, 1, A
B += 1
Next
Locate 1, 1, 0
For A = 1, 21, 1
Locate A, 4, "D"
Next

51
convert.py Normal file
View File

@ -0,0 +1,51 @@
import sys
import os
def rem_empty(data):
return [v for v in data if v]
class PreprocessorError(ValueError):
pass
def open_and_preprocess(path, name, main=False):
file = open(f"{path}/{name}", "r")
content = file.read()
defines = dict()
#take care of whitespaces
content_rem = rem_empty(content.split("\n"))
content = []
for line in content_rem:
content += [line.strip()]
#preprocessing
for line in content:
if line[0] == "#": #is process command
line_argv = rem_empty(line[1:].split(" "))
command = line_argv[0].lower()
if command == "name":
if main:
global out_name
out_name = line_argv[1]
elif command == "include":
open_and_preprocess(path, " ".join(line_argv[1:]))
elif command == "define":
defines[line_argv[1]] = " ".join(line_argv[2:])
else:
raise PreprocessorError(f"{command} preprocessor unknown")
else:
print(line)
temp = open(".temp", "w")
stdout = sys.stdout
sys.stdout = temp
path = "."
name = "main.bc"
out_name = None
open_and_preprocess(path, name, main=True)
sys.stdout = stdout
temp.close()
if not out_name:
raise PreprocessorError("#name <name> preprocessor missing")
else:
os.replace(".temp", f"{out_name}.txt")

3
example.bc Normal file
View File

@ -0,0 +1,3 @@
#name EXAMPLE
Locate 1, 1, 0
#include test.bc

11
main.bc Normal file
View File

@ -0,0 +1,11 @@
#name MAIN
#define test 20
List 1 = {5, 6, 7}
B = 0
For A = 1 To 5 Step 2
Locate A, 1, A
B += 1
Next
#include example.bc

3
test.bc Normal file
View File

@ -0,0 +1,3 @@
For A = 1, 21, 1
Locate A, 4, "D"
Next