aboutsummaryrefslogtreecommitdiff
path: root/bash/step2_eval.sh
diff options
context:
space:
mode:
authorJoel Martin <github@martintribe.org>2014-04-19 13:04:09 -0500
committerJoel Martin <github@martintribe.org>2014-04-19 13:04:09 -0500
commit86b689f3d7111a9fa13da389a30f3dfdf877d1a4 (patch)
treed72b065f9f987e291f892ceee5a8640363bfd9df /bash/step2_eval.sh
parent718887c3019c49fc807bc18fbd5feb975ec03c85 (diff)
downloadmal-86b689f3d7111a9fa13da389a30f3dfdf877d1a4.tar.gz
mal-86b689f3d7111a9fa13da389a30f3dfdf877d1a4.zip
All: *ARGV* and *host-language*. Misc syncing/fixes.
Diffstat (limited to 'bash/step2_eval.sh')
-rwxr-xr-xbash/step2_eval.sh22
1 files changed, 10 insertions, 12 deletions
diff --git a/bash/step2_eval.sh b/bash/step2_eval.sh
index 4572223..224f181 100755
--- a/bash/step2_eval.sh
+++ b/bash/step2_eval.sh
@@ -1,16 +1,15 @@
#!/bin/bash
-INTERACTIVE=${INTERACTIVE-yes}
-
source $(dirname $0)/reader.sh
source $(dirname $0)/printer.sh
-# READ: read and parse input
+# read
READ () {
[ "${1}" ] && r="${1}" || READLINE
READ_STR "${r}"
}
+# eval
EVAL_AST () {
local ast="${1}" env="${2}"
#_pr_str "${ast}"; echo "EVAL_AST '${ast}:${r} / ${env}'"
@@ -39,7 +38,6 @@ EVAL_AST () {
esac
}
-# EVAL: evaluate the parameter
EVAL () {
local ast="${1}" env="${2}"
r=
@@ -61,7 +59,7 @@ EVAL () {
eval ${f} ${args}
}
-# PRINT:
+# print
PRINT () {
if [[ "${__ERROR}" ]]; then
_pr_str "${__ERROR}" yes
@@ -72,9 +70,10 @@ PRINT () {
fi
}
-# REPL: read, eval, print, loop
+# repl
declare -A REPL_ENV
REP () {
+ r=
READ "${1}" || return 1
EVAL "${r}" REPL_ENV
PRINT "${r}"
@@ -90,9 +89,8 @@ REPL_ENV["-"]=minus
REPL_ENV["__STAR__"]=multiply
REPL_ENV["/"]=divide
-if [[ -n "${INTERACTIVE}" ]]; then
- while true; do
- READLINE "user> " || exit "$?"
- [[ "${r}" ]] && REP "${r}" && echo "${r}"
- done
-fi
+# repl loop
+while true; do
+ READLINE "user> " || exit "$?"
+ [[ "${r}" ]] && REP "${r}" && echo "${r}"
+done