-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcompile.py
More file actions
49 lines (36 loc) · 1.04 KB
/
compile.py
File metadata and controls
49 lines (36 loc) · 1.04 KB
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import re
varList = []
filepath = 'main.bas'
with open(filepath) as fp:
lines = fp.readlines()
newFilePath="main.txt"
newFile = open(newFilePath, "w")
# Cycle through to plan out all the variables from dim statements and for loops
for line in lines:
# Removes the comments/semicolons/newlines
line = line.split(';')[0]
# Don't process an empty line
if len(line)==1:
continue
if re.findall("dim",line):
regSplit = re.search('dim (.*)', line)
print(regSplit.group(1))
varList.append(regSplit.group(1))
if re.findall("for ",line):
regSplit = re.search('for (.*) from ([0-9]*) to ([0-9]*) step ([0-9]*)',line)
if regSplit==None:
print("For Loop Error")
else:
print(regSplit.group(1))
varList.append(regSplit.group(1))
# Cycle through all the vars and place them in memory
for var in varList:
newFile.write("."+var+"\n")
newFile.write("NOP 00\n")
newFile.write("\n")
for line in lines:
# Removes the comments/semicolons/newlines
line = line.split(';')[0]
# Don't process an empty line
if len(line)==1:
continue