Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class BrainFuck
- {
- /* * *\
- * BrainF*ck Class *
- * By: opsftw *
- \* * */
- public function bf2php($code) {
- $this->bf = "\$cell = array();\n\$curCell = 0;\n\$marker=0;\n";
- foreach(str_split($code) as $char) {
- $this->php .= ($char=='$' ? "\$marker=\$curCell;\n" : '');
- $this->php .= ($char=='@' ? "\$curCell=\$marker;\n" : '');
- $this->php .= ($char==']' ? "}\n" : '');
- $this->php .= ($char=='[' ? "while(1==1){\n\$tmp=\$curCell;\nif(\$cell[\$tmp]==0){ break; }\n" : '');
- $this->php .= ($char=='-' ? "\$cell[\$curCell]--;\n" : '');
- $this->php .= ($char=='<' ? "\$curCell--;\n" : '');
- $this->php .= ($char=='+' ? "\$cell[\$curCell]++;\n" : '');
- $this->php .= ($char=='>' ? "\$curCell++;\n" : '');
- $this->php .= ($char=='.' ? "echo chr(\$cell[\$curCell]);\n" : '');
- $this->php .= ($char=='#' ? "\$cell[\$curCell]=0;\n" : '');
- $this->php .= ($char=='*' ? "unset(\$cell);\n\$cell = array();\n\$curCell=0;\n" : '');
- $this->bits++;
- }
- return $this;
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement