-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
debugger.py
53 lines (48 loc) · 1.4 KB
/
debugger.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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import re
import RULES
VERSION = "1.0.0"
def perform_shallow_analysis(script):
lines = script.split("\n")
errors = []
for i, line in enumerate(lines):
ok = False
for rule in RULES.COMMANDS:
if re.match(rule, line):
ok = True
break
if not ok:
errors.append(i)
return errors
class result():
def __init__(self, status, data) -> None:
self.status = status
self.data = data
def perform_analysis(script:str):
varspace = [0]*65536
imgVars = []
pointers = []
lines = script.split("\n")
for i, line in enumerate(lines):
lines[i] = line.split(" ")
errors = perform_shallow_analysis(script)
if errors:
print("FATAL: Cannot perform deep analysis, because syntax is incorrect")
return result("ERROR", errors)
warnings = []
init_blocks = []
tick_blocks = []
for i, line in enumerate(lines):
if line[0] == "@":
if line[1] == "on_init":
init_blocks.append(i)
if line[1] == "on_tick":
tick_blocks.append(i)
for i in range (1, len(init_blocks)):
warnings.append({
"line": i,
"message": "Duplicate init block. "
})
if warnings:
print("WARNING possible errors found")
return result("WARNING",warnings)
return result("OK", [])