-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathncc.cpp
More file actions
48 lines (47 loc) · 1.16 KB
/
ncc.cpp
File metadata and controls
48 lines (47 loc) · 1.16 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
#include <iostream>
using std::cout;
using std::endl;
#include "Tokenizer/tokenizer.hpp"
#include "code_generator.hpp"
#include "parser.hpp"
using std::ostream;
using std::string;
#include <iomanip>
using std::setw;
#include <vector>
using std::vector;
int main(int argc, char* argv[]) {
vector<Token> tokens;
if (argc != 2) {
cout << "Usage: " << argv[0] << " [Filename]" << endl;
return 0;
}
if (!initialize(argv[1])) exit(-1);
while (Token t = get_token()) tokens.push_back(t);
cleanup();
/*
cout << "| Token Type | Token Value" << endl
<< "+------------+-- - - - - -" << endl;
for (auto& t : tokens) cout << t << endl;
cout << "+------------+-- - - - - -" << endl
<< endl
<< endl
<< "Parsing" << endl; //*/
auto ct = parse(tokens);
if (ct.t->id == ERROR) {
cout << "Parse Failed" << endl << ct << endl;
return 1;
}
cout << "Code tree: " << endl << ct;
cout.flush();
try {
auto prog = generate(ct);
cout << "Code size: " << prog.size() << " bytes." << endl
<< "Code execution:" << endl;
prog();
cout << endl << endl;
} catch (std::string err) {
cout << "Parsing Error : " << err << endl;
}
cout.flush();
}