- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
#include <iostream>
#define caseop(op, code) case op: code; break;
#define clamp(a, lo, hi) (a < lo) ? (a = lo) : (a > hi) ? (a = hi) : a;
void main(int argc, char* args[]) {
FILE *srcfile = fopen(argc > 1 ? args[1] : "", "r");
(!srcfile) ? exit(0) : fseek(srcfile, 0, SEEK_END);
unsigned char bytes[1024], *byte = bytes;
int x = ftell(srcfile), bs = sizeof(bytes);
rewind(srcfile);
char *source = new char[x + 1], *token = source, *ret = token;
fread(source, sizeof(char), x, srcfile);
memset(&bytes, source[x] = (char)fclose(srcfile), bs--);
do {
switch(*token) {
caseop('+', ++(*byte));
caseop('-', --(*byte));
caseop('.', std::cout << *byte);
caseop(':', std::cout << (int)*byte);
caseop(',', std::cin >> *byte);
caseop('>', clamp(++byte, bytes, &bytes[bs]));
caseop('<', clamp(--byte, bytes, &bytes[bs]));
caseop('[', if (*byte == (x = 1) - 1) while ((*token++) && (x += *token == '[' ? 1 : *token == ']' ? -1 : 0)); else ret = token);
caseop(']', if (*byte) token = ret);
}
} while(*token++);
delete source;
}
guest8 09.04.2019 12:50 # −999