blob: 5e460497fcf1ccebc1a586304f6805cc746d7429 (
plain)
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
54
55
56
57
58
59
|
from lexer import lex
from parser import parse
from runner import evaluate
from std import _get_debug
import sys
def main():
if len(sys.argv) != 2:
print("usage: neb <file>")
sys.exit(1)
with open(sys.argv[1], "r") as fil:
data = fil.read()
try:
lexed = lex(data, [])
'''
if _get_debug():
acc = " ".join([f"{l}" for l in lexed])
print(f" - LEX: {acc}")
'''
parsed = parse(lexed, [])
'''
if _get_debug():
acc = " ".join([f"{p}" for p in parsed])
print(f" - PARSE: {acc}")
'''
ev = evaluate(parsed, [])
except Exception as e:
print(f"panic! {e}")
'''
print("### neb :)(:")
print("version: < 0")
idx = 1
while True:
inp = input(f"#{idx}> ")
if len(inp.strip()) == 0:
continue
try:
lexed = lex(inp, [])
if _get_debug():
acc = " ".join([f"{l}" for l in lexed])
print(f" - LEX: {acc}")
parsed = parse(lexed, [])
if _get_debug():
acc = " ".join([f"{p}" for p in parsed])
print(f" - PARSE: {acc}")
ev = evaluate(parsed, [])
print(f"=> {ev}")
idx += 1
except Exception as e:
print(f"panic! {e}")
'''
if __name__ == "__main__":
main()
|