-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathrepl.erl
More file actions
27 lines (23 loc) · 878 Bytes
/
repl.erl
File metadata and controls
27 lines (23 loc) · 878 Bytes
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
-module(repl).
-compile(export_all).
-import(parse).
-import(connive).
start() ->
c:c(parse),
c:c(connive),
G = [["+", fun([A, B]) -> A + B end], ["-", fun([A, B]) -> A - B end],
["*", fun([A, B]) -> A * B end], ["/", fun([A, B]) -> A / B end],
[">", fun([A, B]) -> A > B end], ["<", fun([A, B]) -> A < B end],
[">=", fun([A, B]) -> A >= B end], ["<=", fun([A, B]) -> A =< B end],
["length", fun(A) -> length(A) end], ["true", fun(_) -> true end],
["false", fun(_) -> false end]],
Global = connive:build_global(G, dict:new()),
run(Global).
run(Env) ->
Exp = string:strip(io:get_line("connive> "), right, $\n),
case Exp of
"(exit)" -> ok;
_ -> {Value, Env2} = connive:eval(parse:parse(Exp), Env),
io:format("~p~n", [Value]),
run(Env2)
end.