Merge pull request #514 from alimpfard/jq-fix
[jackhill/mal.git] / impls / awk / step1_read_print.awk
CommitLineData
8c7587af
MK
1@include "types.awk"
2@include "reader.awk"
3@include "printer.awk"
4
5function READ(str)
6{
7 return reader_read_str(str)
8}
9
10function EVAL(ast)
11{
12 return ast
13}
14
15function PRINT(expr)
16{
17 return printer_pr_str(expr, 1)
18}
19
20function rep(str, ast, expr)
21{
22 ast = READ(str)
23 if (ast ~ /^!/) {
24 return ast
25 }
26 expr = EVAL(ast)
27 if (expr ~ /^!/) {
28 return expr
29 }
30 return PRINT(expr)
31}
32
33function main(str, ret)
34{
35 while (1) {
36 printf("user> ")
37 if (getline str <= 0) {
38 break
39 }
40 ret = rep(str)
41 if (ret ~ /^!/) {
42 print "ERROR: " printer_pr_str(substr(ret, 2))
43 } else {
44 print ret
45 }
46 }
47}
48
49BEGIN {
50 main()
51 exit(0)
52}