├── derp.php └── README.md /derp.php: -------------------------------------------------------------------------------- 1 | 6 | * 7 | * @license Public Domain 8 | * @version 0.1 9 | * @link https://github.com/TheRaz/DerpPlusPlus 10 | */ 11 | class derpplusplus { 12 | 13 | public $pointer = 0; 14 | public $memory; 15 | public $program; 16 | public $position; 17 | 18 | public function __construct() { 19 | $this->memory = array_fill(0, 30000, 0); 20 | } 21 | public function interpret($code,$input = '') { 22 | $code = str_replace(array('HERP', 'DERP', 'HURR', 'DURR', 'GIGGITY', 'GOO', 'WOOPY', 'DOO'),array('HERPQ', 'DERPQ', 'HURRQ', 'DURRQ', 'GIGGITYQ', 'GOOQ', 'WOOPYQ', 'DOOQ'),$code); 23 | $this->program = explode('Q',$code); 24 | $input = str_split($input); 25 | $input_position = 0; 26 | 27 | for($this->position = 0; $this->position < count($this->program); $this->position++) { 28 | $operation = strtoupper($this->program[$this->position]); 29 | switch($operation) { 30 | case 'HERP': 31 | $this->pointer++; 32 | break; 33 | case 'DERP': 34 | $this->pointer--; 35 | break; 36 | case 'HURR': 37 | $this->memory[$this->pointer]++; 38 | break; 39 | case 'DURR': 40 | $this->memory[$this->pointer]--; 41 | break; 42 | case 'GIGGITY': 43 | print chr($this->memory[$this->pointer]); 44 | break; 45 | case 'GOO': 46 | if(isset($input[$input_position])) { 47 | $this->memory[$this->pointer] = ord($input[$input_position]); 48 | } 49 | $input_position++; 50 | break; 51 | case 'WOOPY': 52 | if(!$this->memory[$this->pointer]) { 53 | $counter = 1; 54 | while($counter) { 55 | switch($this->program[++$this->position]) { 56 | case 'WOOPY': 57 | ++$counter; 58 | break; 59 | case 'DOO': 60 | --$counter; 61 | break; 62 | } 63 | } 64 | } 65 | break; 66 | case 'DOO': 67 | $counter = 1; 68 | while($counter) { 69 | switch($this->program[--$this->position]) { 70 | case 'DOO': 71 | ++$counter; 72 | break; 73 | case 'WOOPY': 74 | --$counter; 75 | break; 76 | } 77 | } 78 | --$this->position; 79 | break; 80 | } 81 | } 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | DerpPlusPlus 2 | ============ 3 | 4 | 5 | Please give BrainfuckPHP a visit instead! 6 | ========================================= 7 | Please note that this project was started at 03:00, will most likely be worked on 03:00 and therefor the codequality will suffer. 8 | *** 9 | 10 | Derp++ is a PHP Interpreter for a Brainfuck-ish Language, the difference is the change of which operators are used. 11 | 12 | 13 | | Operator | Function | 14 | |:---------|--------------------------------------------:| 15 | | HERP | Moves pointer 1 cell to the right | 16 | | DERP | Moves pointer 1 cell to the left | 17 | | HURR | Adds 1 to the current cell | 18 | | DURR | Subtracts 1 from the current cell | 19 | | GIGGITY | Prints Ascii representation of current cell | 20 | | GOO | Inputs Ascii value of input character | 21 | 22 | ##### WOOPY 23 | > if the value at the current cell is zero, then instead of moving the instruction pointer forward to the next command, jump it forward to the command after the matching DOO command. 24 | 25 | ##### DOO 26 | > if the valuue at the current cell is > 0, then instead of moving the instruction pointer forward to the next command, jump it back to the command after the matching WOOPY command. 27 | 28 | 29 | Useage 30 | ====== 31 | ```php 32 | $derp = new derpplusplus(); 33 | $derp->interpret('DERP++ Code'); 34 | ``` 35 | 36 | 37 | 38 | Code examples 39 | ============= 40 | ###### Printing the alphabet 41 | ``` 42 | HURRHURRHURRHURRHURRWOOPYHERPHURRHURRHURRHURRHURRHURRHURRHURRHURRHURRHURRHURRHURRDERPDURRDOOHERPGIGGITYHURRGIGGITYHURRGIGGITYHURRGIGGITYHURRGIGGITYHURRGIGGITYHURRGIGGITYHURRGIGGITYHURRGIGGITYHURRGIGGITYHURRGIGGITYHURRGIGGITYHURRGIGGITYHURRGIGGITYHURRGIGGITYHURRGIGGITYHURRGIGGITYHURRGIGGITYHURRGIGGITYHURRGIGGITYHURRGIGGITYHURRGIGGITYHURRGIGGITYHURRGIGGITYHURRGIGGITYHURRGIGGITY 43 | ``` 44 | 45 | ###### Hello World! 46 | ``` 47 | HURRHURRHURRHURRHURRHURRHURRHURRHURRHURRWOOPYHERPHURRHURRHURRHURRHURRHURRHURRHERPHURRHURRHURRHURRHURRHURRHURRHURRHURRHURRHERPHURRHURRHURRHERPHURRDERPDERPDERPDERPDURRDOOHERPHURRHURRGIGGITYHERPHURRGIGGITYHURRHURRHURRHURRHURRHURRHURRGIGGITYGIGGITYHURRHURRHURRGIGGITYHERPHURRHURRGIGGITYDERPDERPHURRHURRHURRHURRHURRHURRHURRHURRHURRHURRHURRHURRHURRHURRHURRGIGGITYHERPGIGGITYHURRHURRHURRGIGGITYDURRDURRDURRDURRDURRDURRGIGGITYDURRDURRDURRDURRDURRDURRDURRDURRGIGGITYHERPHURRGIGGITYHERPGIGGITY 48 | 49 | ``` 50 | 51 | --------------------------------------------------------------------------------