Execute Brain****/C++: Difference between revisions
m
Fixed syntax highlighting.
(Behold, a piece of software written for RC.) |
m (Fixed syntax highlighting.) |
||
(22 intermediate revisions by 9 users not shown) | |||
Line 1:
{{implementation|Brainf***}}{{collection|RCBF}}
It may be fed BF instructions either through standard input (i.e. terminal keyboard input), or through a file named as the first command-line argument.
RCBF is intended for educational purposes only; There is no guarantee it won't lock up your computer. (Though Mike M thinks he's got that bug ironed out...) (We'll no it wasn't, but it should be now -- RdB)
{{works with|g++|4.1.3}}
<
▲<pre>// RCBF -- A free Brainfuck interpreter written for Rosetta Code (http://rosettacode.org)
// Created by Mike Mol and Mike Neurohr, and under the same license as Rosetta Code.
// Repaired by Robert de Bath -- but Ghods is it slow!
// Test with this Hello World, it breaks BF interpreters
// >++++++++[<+++++++++>-]<.>>+>+>++>[-]+<[>[->+<<++++>]<<]>.+++++++..+++.>
// >+++++++.<<<[[-]<[-]>]<+++++++++++++++.>>.+++.------.--------.>>+.>++++.
#include <list>
Line 19 ⟶ 24:
#define ERROR_BRANCH_OPEN_NOT_MATCHED 3
#define ERROR_BRANCH_CLOSE_NOT_MATCHED 4
#define ERROR_FILE_LOAD_FAILED 5
using namespace std;
Line 82 ⟶ 88:
{
file.open(argv[1]);
// If the file failed to load, we need to abort.
{
cerr << "File load failed" << endl;
return ERROR_FILE_LOAD_FAILED;
}
source = &file;
Line 231 ⟶ 244:
int input(memptr_t &ptr)
{
▲ if ( cin.eof() )
return SUCCESS;
}
Line 337 ⟶ 345:
codeptr_t tmppos = code.end();
rec.open = --tmppos;
rec.close = rec.open;
// Because we always encounter forward jumps before back jumps,
Line 386 ⟶ 395:
// We never found a close branch
return BRANCH_NOT_FOUND;
}</
|