2020-05-28 04:55:58 +00:00
|
|
|
<?php
|
|
|
|
namespace MadLisp;
|
|
|
|
|
|
|
|
class Lisp
|
|
|
|
{
|
2020-05-28 10:10:00 +00:00
|
|
|
protected Tokenizer $tokenizer;
|
|
|
|
protected Reader $reader;
|
|
|
|
protected Evaller $eval;
|
|
|
|
protected Printer $printer;
|
2020-06-17 10:24:15 +00:00
|
|
|
protected Env $env;
|
2020-05-28 09:49:32 +00:00
|
|
|
|
2020-06-17 10:24:15 +00:00
|
|
|
public function __construct(Tokenizer $tokenizer, Reader $reader, Evaller $eval, Printer $printer, Env $env)
|
2020-05-28 04:55:58 +00:00
|
|
|
{
|
2020-05-28 10:10:00 +00:00
|
|
|
$this->tokenizer = $tokenizer;
|
|
|
|
$this->reader = $reader;
|
|
|
|
$this->eval = $eval;
|
|
|
|
$this->printer = $printer;
|
2020-06-17 10:24:15 +00:00
|
|
|
$this->env = $env;
|
2020-05-28 07:40:54 +00:00
|
|
|
}
|
|
|
|
|
2020-06-17 10:24:15 +00:00
|
|
|
public function rep(string $input, bool $printReadable): void
|
2020-05-28 07:40:54 +00:00
|
|
|
{
|
2020-05-28 10:10:00 +00:00
|
|
|
$tokens = $this->tokenizer->tokenize($input);
|
2020-05-28 07:40:54 +00:00
|
|
|
|
2020-06-04 02:10:48 +00:00
|
|
|
$expr = $this->reader->read($tokens);
|
2020-05-28 07:40:54 +00:00
|
|
|
|
2020-06-17 10:24:15 +00:00
|
|
|
$result = $this->eval->eval($expr, $this->env);
|
2020-05-28 04:55:58 +00:00
|
|
|
|
2020-06-16 13:38:46 +00:00
|
|
|
$this->printer->print($result, $printReadable);
|
2020-05-28 04:55:58 +00:00
|
|
|
}
|
|
|
|
}
|