mirror of
https://github.com/peklaiho/madlisp.git
synced 2024-11-22 21:35:03 +00:00
32 lines
719 B
PHP
32 lines
719 B
PHP
<?php
|
|
require('vendor/autoload.php');
|
|
|
|
function ml_get_lisp(): array
|
|
{
|
|
$tokenizer = new MadLisp\Tokenizer();
|
|
$reader = new MadLisp\Reader();
|
|
$eval = new MadLisp\Evaller();
|
|
$printer = new MadLisp\Printer();
|
|
|
|
$lisp = new MadLisp\Lisp($tokenizer, $reader, $eval, $printer);
|
|
|
|
// environment
|
|
|
|
$env = new MadLisp\Env();
|
|
|
|
$core = new MadLisp\Lib\Core();
|
|
$core->register($env);
|
|
|
|
$env->set('eval', function (...$args) use ($eval, $env) {
|
|
$results = $eval->eval($args, $env);
|
|
return $results[count($results) - 1];
|
|
});
|
|
|
|
$env->set('print', function (...$args) use ($printer) {
|
|
$printer->print($args);
|
|
return null;
|
|
});
|
|
|
|
return [$lisp, $env];
|
|
}
|