-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathbfmin.cpp
More file actions
54 lines (50 loc) · 973 Bytes
/
Copy pathbfmin.cpp
File metadata and controls
54 lines (50 loc) · 973 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
45
46
47
48
49
50
51
52
53
54
#include <iostream>
using namespace std;
int main(int argc, char* argv[]){
char byte;
bool newline = true;
int line = 1;
int loops = 0;
while(!cin.eof()){
cin.read(&byte, 1);
if(!newline && byte != '\n'){
continue;
}
switch(byte){
case '\n':
newline = true;
++line;
continue;
case ' ':
case '\t':
continue;
case '>':
case '<':
case '+':
case '-':
case '.':
case ',':
break;
case '[':
++loops;
if(loops > 62){
cerr << "bfmin: Warning: stack overflow: the loop stack in brainfuck-cpu does not support more than 62 loops" << endl;
}
break;
case ']':
--loops;
if(loops < 0){
cerr << "bfmin: Warning: syntax error: unmatched ] on line " << line << endl;
}
break;
default:
newline = false;
continue;
}
cout.write(&byte, 1);
}
if(loops > 0){
cerr << "bfmin: Warning: strict error: end of file reached with an unclosed [" << endl;
}
return 0;
}