-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbfc.cpp
More file actions
50 lines (42 loc) · 1.07 KB
/
Copy pathbfc.cpp
File metadata and controls
50 lines (42 loc) · 1.07 KB
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
#include <iostream>
#include <fstream>
#include <string>
#include <unordered_map>
int main(int argc, char* argv[]) {
if (argc != 3) {
std::cerr << "Usage: bfc_compiler <input.bfc> <output.bfp>" << std::endl;
return 1;
}
std::string inputFile = argv[1];
std::string outputFile = argv[2];
std::ifstream in(inputFile);
if (!in) {
std::cerr << "Error opening input file: " << inputFile << std::endl;
return 1;
}
std::ofstream out(outputFile, std::ios::binary);
if (!out) {
std::cerr << "Error opening output file: " << outputFile << std::endl;
return 1;
}
std::unordered_map<char, char> mapping = {
{'>', 0},
{'<', 1},
{'+', 2},
{'-', 3},
{'.', 4},
{',', 5},
{'[', 6},
{']', 7}
};
char ch;
while (in.get(ch)) {
if (mapping.count(ch)) {
out.put(mapping[ch]);
}
}
in.close();
out.close();
std::cout << "Compiled " << inputFile << " to " << outputFile << std::endl;
return 0;
}