aboutsummaryrefslogtreecommitdiff
path: root/php/step0_repl.php
diff options
context:
space:
mode:
Diffstat (limited to 'php/step0_repl.php')
-rw-r--r--php/step0_repl.php33
1 files changed, 33 insertions, 0 deletions
diff --git a/php/step0_repl.php b/php/step0_repl.php
new file mode 100644
index 0000000..64b086b
--- /dev/null
+++ b/php/step0_repl.php
@@ -0,0 +1,33 @@
+<?php
+
+require_once 'readline.php';
+
+// read
+function READ($str) {
+ return $str;
+}
+
+// eval
+function MAL_EVAL($ast, $env) {
+ return eval($ast);
+}
+
+// print
+function MAL_PRINT($exp) {
+ return var_export($exp, true) . "\n";
+}
+
+// repl
+function rep($str) {
+ return MAL_PRINT(MAL_EVAL(READ($str), array()));
+}
+
+do {
+ $line = mal_readline("user> ");
+ if ($line === NULL) { break; }
+ if (!empty($line)) {
+ print(rep($line));
+ }
+} while (true);
+
+?>