-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMain.cpp
More file actions
107 lines (79 loc) · 2.17 KB
/
Copy pathMain.cpp
File metadata and controls
107 lines (79 loc) · 2.17 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#include <iostream>
#include <vector>
#include <random>
#include <map>
#include <unordered_map>
#include <functional>
#include <bitset>
#include <set>
#include <numeric>
#include <fstream>
#include <iterator>
#include <string>
#include <filesystem>
#include "ExplorTypes.h"
#include "parsing/ExplorParser.h"
#include "ExplorLang.h"
namespace fs = std::filesystem;
int main(int argc, char** argv) {
std::ifstream example;
if(argc == 1){
std::cout << "Input file missing";
exit(0);
}
//Check if file exists
auto path = fs::path(argv[1]);
if (!fs::exists(path)) {
std::cout << "Invalid path specified or File does not exist";
exit(0);
}
example.open(path.filename(), std::ifstream::in);
using ctxFileIter = ContextAwareIterator<std::istreambuf_iterator<char>,16,GenericContext<std::string>>;
std::istreambuf_iterator<char> eof;
ctxFileIter s = std::istreambuf_iterator<char>(example);
ctxFileIter e = eof;
auto result = new decltype(pattern)::return_type;
bool hasParsed = pattern(s, e, result);
if (s != e) {
std::cout << "Failed to parse file";
std::cout << "Ended @ " << s.line() << '#' << s.column() << '\n';
std::cout << "Read " << result->size() << " Lines" << std::endl;
exit(1);
}
if (hasParsed) {
auto program = new EXPLOR<320,240>;
for(auto & line: *result) {
std::apply([&program](std::string label,Commands command) {
program->addLine(label, command);
}, line);
}
try {
program->execute();
}
catch (std::exception & e) {
//Print Error
std::cout << "\nEncountered Error -> " << e.what();
}
std::ofstream example_out;
auto out_path = std::string("./");
out_path.append(path.stem().generic_string().append(".pbm"));
std::cout << "Output 1 Frame to: " << out_path;
if (program->frames.size() != 0) {
example_out.open(out_path, std::ofstream::out);
auto& fframe = program->frames[0];
example_out << "P1 320 240 1\n";
for (size_t i = 0; i < fframe.size(); i++)
{
for (size_t j = 0; j < fframe[i].size(); j++)
{
example_out << fframe.at(i).at(j) << " ";
}
}
example_out.close();
}
else {
std::cout << "No frames generated\n";
}
}
example.close();
};