1
1
mirror of https://github.com/kanaka/mal.git synced 2024-11-11 00:52:44 +03:00
mal/awk/step1_read_print.awk
2015-08-26 10:13:25 +09:00

53 lines
623 B
Awk

@include "types.awk"
@include "reader.awk"
@include "printer.awk"
function READ(str)
{
return reader_read_str(str)
}
function EVAL(ast)
{
return ast
}
function PRINT(expr)
{
return printer_pr_str(expr, 1)
}
function rep(str, ast, expr)
{
ast = READ(str)
if (ast ~ /^!/) {
return ast
}
expr = EVAL(ast)
if (expr ~ /^!/) {
return expr
}
return PRINT(expr)
}
function main(str, ret)
{
while (1) {
printf("user> ")
if (getline str <= 0) {
break
}
ret = rep(str)
if (ret ~ /^!/) {
print "ERROR: " printer_pr_str(substr(ret, 2))
} else {
print ret
}
}
}
BEGIN {
main()
exit(0)
}