-
Notifications
You must be signed in to change notification settings - Fork 0
/
repl.php
33 lines (29 loc) · 873 Bytes
/
repl.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
<?php
include("urlisp.php");
$env = standard_env();
$symbs = $env->bound();
$symb_lst = '';
foreach ($symbs as $s)
$symb_lst .= "<li>{$s}</li>";
if ($_SERVER['REQUEST_METHOD'] === 'GET') {
$ctx = array('repltext' => '', 'symbol_lst' => $symb_lst);
echo include 'template.php';
} else if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$code = $_POST['code'];
$l = LexSexpr($code);
$ast = parse_sexpr($l);
$result = '';
if ($ast instanceof SysError) {
$result = sprintf("%s\n\n=> %s\n", $code, $val);
}
else {
// Just want the success sexpr we just parsed, not any trailing
// junk
$code = join('', array_slice($l->input, 0, $l->start));
$val = $ast->evaluate(standard_env());
$result = sprintf("%s\n\n=> %s\n", $code, $val);
}
$ctx = array('repltext' => $result, 'symbol_lst' => $symb_lst);
echo include 'template.php';
}
?>