echo $begrüßung;
Ach, Brainfuck... Whitespace ist noch cooler. Da das Forum aber mit Whitespace-Code nicht sehr pfleglich umgeht, gibts hier meinen eben auf die Schnelle zusammengehackten Brainfuck-Interpreter. (PHP 5 erforderlich)
<?php
$code = <<<CODE
+++[>++++[->++++++<]<-]>>.<++[>---<-]>-.<+++[->+++<
]>++..+++.<<++++[->+++++[->--<]<]>+++[>--<-]>-.<<++
++++[->>+++++++++<<]>>--.-----.<++++[>----<-]>+++.<
+++[->++<]>+.<+++[->---<]>+.<<+++[->++[->+++<]<]>>.
CODE;
$bf = new BrainFuck($code);
$bf->Run();
class BrainFuck {
private $code = null;
private $data = array();
private $dataPointer = 0;
private $codePointer = 0;
private $jumps = 0;
function __construct($code = null) {
$this->data = array();
$this->dataPointer = 0;
$this->codePointer = 0;
$this->jumps = 0;
if (!is_null($code))
$this->code = $code;
} //BrainFuck::__construct
private function Data($value = 0) {
if (!isset($this->data[$this->dataPointer]))
$this->data[$this->dataPointer] = 0;
if ($value > 0)
$this->data[$this->dataPointer]++;
if ($value < 0)
$this->data[$this->dataPointer]--;
if ($value == 0)
return $this->data[$this->dataPointer];
} //BrainFuck::Data
private function jumpAhead() {
$jumps = $this->jumps++;
while (++$this->codePointer < strlen($this->code)) {
switch ($this->code{$this->codePointer}) {
case '[': $this->jumps++; break;
case ']': if (--$this->jumps == $jumps) return;
} //switch
} //while
die('Error: unexpected end of code');
} //BrainFuck::jumpAhead
private function jumpBack() {
$jumps = $this->jumps--;
while (--$this->codePointer > 0) {
switch ($this->code{$this->codePointer}) {
case ']': $this->jumps--; break;
case '[': if (++$this->jumps == $jumps) return;
} //switch
} //while
die('Error: begin of code exceeded');
} //BrainFuck::jumpBack
function Run() {
$this->__construct(); // reset values if called more than once
if (!strlen($this->code))
die('Error: no code');
do {
switch ($this->code{$this->codePointer}) {
case '>': $this->dataPointer++; break;
case '<': $this->dataPointer--; break;
case '+': $this->Data(1); break;
case '-': $this->Data(-1); break;
case '.': echo chr($this->Data()); break;
case ',': break; // not implemented
case '[': (!$this->Data()) ? $this->jumpAhead() : $this->jump++; break;
case ']': ($this->Data()) ? $this->jumpBack() : $this->jump--; break;
} //switch
} while (++$this->codePointer < strlen($this->code));
} //BrainFuck::Run
} //BrainFuck
?>
echo "$verabschiedung $name";