-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
45 lines (39 loc) · 1014 Bytes
/
main.cpp
File metadata and controls
45 lines (39 loc) · 1014 Bytes
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
#include <iostream>
#include <fstream>
#include <sstream>
#include "lexer.h"
#include "parser.h"
char* FILE_NAME;
std::string code;
std::vector<Token>* tokens;
SyntaxTreeNode tree;
int main(int argc, char* argv[]) {
if (argc <= 1) {
std::cout << "ERROR: filename (argument 1) required \n";
exit(1);
}
FILE_NAME = argv[1];
//// read file:
std::ifstream file(FILE_NAME);
if (!file.is_open()) {
std::cout << "ERROR: could not open \"" << FILE_NAME << "\"\n";
exit(1);
}
std::stringstream buffer;
buffer << file.rdbuf();
code = buffer.str();
file.close();
//// generate tokens (lexer):
Lexer lexer(code, FILE_NAME);
lexer.tokenize();
lexer.condense();
tokens = lexer.return_tokens();
//// validate & generate syntax trees (parser):
Parser parser(tokens, code, FILE_NAME);
parser.syntactical_analysis();
parser.semantical_analysis();
tree = parser.get_syntax_tree();
//// optimize tree (optimizer):
//// compile tree (assembler):
//// output executable (.asm or .c file for now):
}