-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrepl.py
More file actions
53 lines (43 loc) · 1.08 KB
/
Copy pathrepl.py
File metadata and controls
53 lines (43 loc) · 1.08 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
49
50
51
52
53
import readline
import sys
from pprint import pprint
import h4x
h4x.DEBUG = False
scopes = h4x.create_scopes()
h4x.import_stdlib(scopes)
def func_exit(args, scopes):
print("Goodbye!")
sys.exit()
def func_debug(args, scopes):
h4x.DEBUG = not h4x.DEBUG
if h4x.DEBUG:
print("Debug mode activated")
else:
print("Debug mode disabled")
scopes[0]["exit"] = h4x.datatypes.PyExec(func_exit, 0)
scopes[0]["quit"] = scopes[0]["exit"]
scopes[0]["debug"] = h4x.datatypes.PyExec(func_debug, 0)
scopes[0][""] = h4x.datatypes.Null()
canceled = "="
while True:
try:
program = input(canceled + "> ") + "\n"
tokenized = h4x.tokenize(program)
while not h4x.parser.is_valid_program(tokenized):
program += input(canceled + "] ") + "\n"
tokenized = h4x.tokenize(program)
except KeyboardInterrupt:
print()
canceled = "-"
continue
except h4x.error.H4xError:
continue
canceled = "="
parsed = h4x.tokens_to_tree(tokenized)
try:
evaled = h4x.eval(parsed, scopes)
except h4x.error.H4xError:
evaled = "error"
print("<" + canceled, end=" ")
print(evaled)
#(define plus5 (fn (a) (+ a 5) ) )