mirror of
https://github.com/peklaiho/madlisp.git
synced 2024-11-22 21:35:03 +00:00
38 lines
897 B
PHP
38 lines
897 B
PHP
<?php
|
|
namespace MadLisp;
|
|
|
|
class Lisp
|
|
{
|
|
protected Tokenizer $tokenizer;
|
|
protected Reader $reader;
|
|
protected Evaller $eval;
|
|
protected Printer $printer;
|
|
protected Env $env;
|
|
|
|
public function __construct(Tokenizer $tokenizer, Reader $reader, Evaller $eval, Printer $printer, Env $env)
|
|
{
|
|
$this->tokenizer = $tokenizer;
|
|
$this->reader = $reader;
|
|
$this->eval = $eval;
|
|
$this->printer = $printer;
|
|
$this->env = $env;
|
|
}
|
|
|
|
public function readEval(string $input)
|
|
{
|
|
$tokens = $this->tokenizer->tokenize($input);
|
|
|
|
$expr = $this->reader->read($tokens);
|
|
|
|
return $this->eval->eval($expr, $this->env);
|
|
}
|
|
|
|
// read, eval, print
|
|
public function rep(string $input, bool $printReadable): void
|
|
{
|
|
$result = $this->readEval($input);
|
|
|
|
$this->printer->print($result, $printReadable);
|
|
}
|
|
}
|