~kf5jwc/imp-parser

ref: 9a694fa0d8b73f01beb051b54cdab8a2b000be09 imp-parser/tests/test_imp_interpreter.py -rwxr-xr-x 624 bytes View raw
9a694fa0 — Kyle Jones I've done more type annotating, which.... helped? 1 year, 6 months ago
                                                                                
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
#!/usr/bin/env python

import argparse
import sys

from imp_parser import imp_lex, imp_parse


if __name__ == '__main__':
    parser = argparse.ArgumentParser()
    parser.add_argument("filename", type=argparse.FileType("r"), default=sys.stdin)
    args = parser.parse_args()

    text = args.filename.read()
    tokens = imp_lex(text)
    result = imp_parse(tokens)
    if not result:
        print("Unknown parse error!", file=sys.stderr)
        sys.exit(1)

    ast = result.value
    env = {}
    ast.eval(env)

    print("Final variable values:")
    for name, value in env.items():
        print(f" {name}: {value}")