-
Notifications
You must be signed in to change notification settings - Fork 8
/
main.cpp
42 lines (33 loc) · 1.03 KB
/
main.cpp
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
#include "Tokenizer.hpp"
#include "Parser.hpp"
#include <iostream>
using namespace std;
using namespace simpleparser;
int main() {
try {
std::cout << "simpleparser 0.1\n" << endl;
FILE *fh = fopen("D:\\CLionProjects\\ParserAndCompiler\\simpleparser\\test.myc", "r");
if (!fh) { cerr << "Can't find file." << endl; }
fseek(fh, 0, SEEK_END);
size_t fileSize = ftell(fh);
fseek(fh, 0, SEEK_SET);
string fileContents(fileSize, ' ');
fread(fileContents.data(), 1, fileSize, fh);
cout << fileContents << endl << endl;
Tokenizer tokenizer;
vector<Token> tokens = tokenizer.parse(fileContents);
for(Token currToken : tokens) {
currToken.debugPrint();
}
Parser parser;
parser.parse(tokens);
parser.debugPrint();
} catch (exception& err) {
cerr << "Error: " << err.what() << endl;
return 2;
} catch (...) {
cerr << "Unknown Error." << endl;
return 1;
}
return 0;
}