-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbi-interpret
executable file
·36 lines (30 loc) · 938 Bytes
/
bi-interpret
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
#!/usr/bin/env php
<?php
require_once 'bi.php'; // Require the brainfuck library
if(in_array('-h', $argv) || in_array('-?', $argv) || in_array('--help', $argv)) {
echo "\nUSAGE: ", $argv[0], " [-h | -? | --help | <input file>]\n\n",
"Reads brainfuck code to be interpreted from <input file> (or standard",
"input if no file is specified) then executes the specified program. ",
"If one of -h, -? or --help is specified, print this message then ",
"exit.";
exit;
}
if(count($argv) == 1) {
if(!defined('STDIN')) {
echo "Error: Cannot read from standard input.\n";
exit(1);
}
$inputResource = STDIN;
} else {
$inputResource = fopen($argv[1], 'r', true);
if(!$inputResource) {
echo "Error opening file `", $argv[1], "\n";
exit(1);
}
}
$inputFile = '';
while($line = fgets($inputResource)) {
$inputFile .= $line;
}
$interpreter = new BrainfuckInterpreter();
$interpreter->Interpret($inputFile);