added tips to lamer.bash help
[mirrors/Programs.git] / php / skripty / php_brainfuck.php
CommitLineData
8de51304
H
1<?php\r
2\r
3$code = "++++++++[>+++++++++<-]>.<+++++[>++++++<-]>-.+++++++..+++.<++++++++[>>++++<<-]>>.<<++++[>------<-]>.<++++[>++++++<-]>.+++.------.--------.>+.";\r
4\r
5$buffer = "";\r
6$pos = 0;\r
7$while = array(); // array($i, ...)\r
8for ($i=0; $i < strlen($code); $i++) {\r
9 switch ($code{$i}) {\r
10 case '>': $pos++; break;\r
11 case '<': $pos--; break;\r
12 case '+': $buffer{$pos} = chr(ord($buffer{$pos}) + 1); break;\r
13 case '-': $buffer{$pos} = chr(ord($buffer{$pos}) - 1); break;\r
14 case '.': echo $buffer{$pos}; break;\r
15 case ',': $buffer{$pos} = fgetc(STDIN); break;\r
16 case '[': if (ord($buffer{$pos})) $while[] = $i; else for ($depth=1; $depth; $i++) {\r
17 if ($code{$i+1} == '[') $depth++;\r
18 elseif ($code{$i+1} == ']') $depth--;\r
19 }\r
20 break;\r
21 case ']': $i = array_pop($while) - 1; break;\r
22 default: echo "Unrecognized character.\n"; exit(1);\r
23 }\r
24}\r
25\r
26echo("\n\n");\r
27\r
28?>\r
This page took 0.206073 seconds and 4 git commands to generate.