aboutsummaryrefslogtreecommitdiff
path: root/repl.py
blob: 2846d338f44fb14e3dac05107ac5521b24a33564 (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
from lexer import lex
from parser import parse
from interpreter import interpret

prev_lexed = None
prev_parsed = None

def main():
    print("### neb :)(:")
    print("version: < 0")
    idx = 1
    prev_idx = 0
    while True:
        inp = input(f"#{idx}> ")
        if len(inp.strip()) == 0:
            continue
        try:
            if inp.strip() == "(debug)":
                if prev_lexed is not None:
                    acc = " ".join([f"{l}" for l in prev_lexed])
                    print(f" - LEX:  {acc}")
                if prev_parsed is not None:
                    acc = " ".join([f"{p}" for p in prev_parsed])
                    print(f" - PARSE:  {acc}")
                continue
            lexed = lex(inp)
            prev_lexed = lexed
            parsed = parse(lexed)
            prev_parsed = parsed
            inter = interpret(parsed)
            print(f"=> {inter}")
            prev_idx = idx
            idx += 1
        except Exception as e:
            print(f"panic! {e}")
        

if __name__ == "__main__":
    main()