Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <fstream>
- #include <vector>
- #define CELLS_NUM 30000
- int main()
- {
- unsigned char arr[CELLS_NUM] = {};
- unsigned int current_cell = 0;
- using namespace std;
- string filename;
- cout << "Source:";
- cin >> filename;
- fstream source_file(filename.c_str(), ios_base::in);
- vector<unsigned char>source;
- while (!source_file.eof())
- {
- char ch = 0;
- source_file.get(ch);
- source.push_back(ch);
- }
- source_file.close();
- for (unsigned i = 0; i < static_cast<unsigned>(source.size()); ++i)
- {
- unsigned char ch = source[i];
- switch (ch)
- {
- case '>':
- current_cell++;
- break;
- case '<':
- current_cell--;
- break;
- case '+':
- arr[current_cell]++;
- break;
- case '-':
- arr[current_cell]--;
- break;
- case '.':
- cout << arr[current_cell];
- break;
- case ',':
- cin >> ch;
- arr[current_cell] = ch;
- break;
- case '[':
- if (arr[current_cell] == 0)
- {
- unsigned j = 1;
- while (j != 0)
- {
- i++;
- switch (source[i])
- {
- case '[':
- j++;
- break;
- case ']':
- j--;
- break;
- default:
- break;
- }
- }
- }
- break;
- case ']':
- if (arr[current_cell] != 0)
- {
- unsigned j = 1;
- while (j != 0)
- {
- i--;
- switch (source[i])
- {
- case '[':
- j--;
- break;
- case ']':
- j++;
- break;
- default:
- break;
- }
- }
- }
- break;
- default:
- break;
- }
- }
- system("PAUSE");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement