Haxe: step7-A, hash-maps, metadata, self-hosting.
[jackhill/mal.git] / awk / step1_read_print.awk
1 @include "types.awk"
2 @include "reader.awk"
3 @include "printer.awk"
4
5 function READ(str)
6 {
7 return reader_read_str(str)
8 }
9
10 function EVAL(ast)
11 {
12 return ast
13 }
14
15 function PRINT(expr)
16 {
17 return printer_pr_str(expr, 1)
18 }
19
20 function 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
33 function 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
49 BEGIN {
50 main()
51 exit(0)
52 }