|
|
@ -13,12 +13,17 @@ namespace brainfuck_details { |
|
|
|
template <typename T, typename InputIterator, typename OutputIterator> |
|
|
|
void b(char * c, InputIterator& in, T * & p, OutputIterator out){ |
|
|
|
for(; *c && *c != ']'; ++c) { |
|
|
|
(*((p+=*c=='>')-=*c=='<')+=*c=='+') -=*c=='-'; |
|
|
|
if(*c=='.') *out++ = *p; |
|
|
|
if(*c==',') *p = *in++; |
|
|
|
if(*c=='[') { |
|
|
|
switch(*c){ |
|
|
|
case '>' : ++p; break; |
|
|
|
case '<' : --p; break; |
|
|
|
case '+' : ++*p; break; |
|
|
|
case '-' : --*p; break; |
|
|
|
case '.' : *out++ = *p; break; |
|
|
|
case ',' : *p = *in++; break; |
|
|
|
case '[' : |
|
|
|
for(++c; *p;) b(c, in, p, out); |
|
|
|
for(int d=0; *c!=']'||d--; ++c)d+=*c=='['; |
|
|
|
for(int d = 0; *c!=']' || d--; ++c) if(*c == '[') d++; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|