Merge branch 'ruby1.9' of https://github.com/elektronaut/mal into elektronaut-ruby1.9
[jackhill/mal.git] / php / step1_read_print.php
1 <?php
2
3 require_once 'readline.php';
4 require_once 'types.php';
5 require_once 'reader.php';
6 require_once 'printer.php';
7
8 // read
9 function READ($str) {
10 return read_str($str);
11 }
12
13 // eval
14 function MAL_EVAL($ast, $env) {
15 return $ast;
16 }
17
18 // print
19 function MAL_PRINT($exp) {
20 return _pr_str($exp, True) . "\n";
21 }
22
23 // repl
24 function rep($str) {
25 return MAL_PRINT(MAL_EVAL(READ($str), array()));
26 }
27
28 // repl loop
29 do {
30 try {
31 $line = mal_readline("user> ");
32 if ($line === NULL) { break; }
33 if ($line !== "") {
34 print(rep($line));
35 }
36 } catch (BlankException $e) {
37 continue;
38 } catch (Exception $e) {
39 echo "Error: " . $e->getMessage() . "\n";
40 echo $e->getTraceAsString() . "\n";
41 }
42 } while (true);
43
44 ?>