-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathbf2php.php
More file actions
executable file
·47 lines (39 loc) · 795 Bytes
/
bf2php.php
File metadata and controls
executable file
·47 lines (39 loc) · 795 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/usr/bin/env php
<?php
echo '<?php' . PHP_EOL;
echo '$dseg = array();' . PHP_EOL;
echo '$dseg[0] = 0;' . PHP_EOL;
echo '$pc = 0;' . PHP_EOL;
echo '$dx = 0;' . PHP_EOL;
$stdin = file_get_contents("php://stdin");
for ($i = 0; $i < strlen($stdin); $i++) {
$ch = $stdin[$i];
switch ($ch) {
case '>':
echo '$dx++;' . PHP_EOL;
echo 'if (isset($dseg[$dx]) == FALSE) $dseg[$dx] = 0;' . PHP_EOL;
break;
case '<':
echo '$dx--;' . PHP_EOL;
break;
case '+':
echo '$dseg[$dx]++;' . PHP_EOL;
break;
case '-':
echo '$dseg[$dx]--;' . PHP_EOL;
break;
case '.':
echo 'print chr($dseg[$dx]);' . PHP_EOL;
break;
case ',':
// input from user
break;
case '[':
echo 'while ($dseg[$dx] != 0) {' . PHP_EOL;
break;
case ']':
echo '}' . PHP_EOL;
break;
default:
}
}