Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Brainfuck Interpreter by Charles Ray Shisler III
- #include <iostream>
- #include <fstream>
- #define y int&s,char*v,int*a,std::istream&f,int&p,char&c
- void x(y){v[s]=((v[s]<255)?v[s]+1:0);} // +
- void t(y){s=((s<99998)?s+1:0);} // >
- void q(y){v[s]=((v[s]>0)?v[s]-1:255);} // -
- void k(y){s=((s>0)?s-1:99998);} // <
- void e(y){std::cout<<v[s];} // .
- void h(y){char e=(char)std::cin.get(); // ,
- v[s]=(e==10)?0:e;}
- void o(y){if(v[s])a[p++]=f.tellg(); // [
- else for(int d=0;c!=93&&d>0;d=c==91?d+1:c==93?d-1:d)f.get(c);}
- void i(y){if(v[s])f.seekg(a[--p]-1);} // ]
- void w(y){return;} // NOP
- int main(int g,char**r){
- if(g<2)return 1;
- std::ifstream f(r[1]);
- if(!f)return 1;
- char c=0,v[99999]={0};
- void (*n)(int&,char*,int*,std::istream&,int&,char&)=&w;
- for(int s=0,p=0,a[1000]={0};f.peek()!=-1;f.get(c),n=(c==43?&x:c==45?&\
- q:c==62?&t:c==60?&k:c==46?&e:c==44?&h:c==91?&o:c==93?&i:&w))(*n)(s,v,a,f,p,c);
- f.close();
- return 0;}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement