-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
61 lines (58 loc) · 1.94 KB
/
main.cpp
File metadata and controls
61 lines (58 loc) · 1.94 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
#include <iostream>
#include <token/token.hpp>
#include <lexer/lexer.hpp>
#include <interpreter/interpreter.hpp>
#include <symbol/symbolTableBuilder.hpp>
#include <callStack/callStack.hpp>
#include <chrono>
#include <fstream>
#include <filesystem>
#include <bootstrap/bootstrap.hpp>
void run(std::string input)
{
input = Bootstrap::bootstrapArray()+ Bootstrap::bootstrapMap() + Bootstrap::bootstrapString() + input;
// std::cout << std::endl
// << input
// << std::endl
// << std::endl;
auto start = std::chrono::high_resolution_clock::now();
Lexer lexer{input};
Parser parser{lexer};
SymbolTableBuilder stb{parser};
auto st = stb.build();
//st->print();
CallStack callStack{st};
Interpreter interpreter{&parser, callStack};
interpreter.interpret();
std::cout << std::endl
<< std::endl;
auto end = std::chrono::high_resolution_clock::now();
std::cout << "executed successfully in " << std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count() << " millisecond ........" << std::endl
<< std::endl;
// // std::cout << std::endl
// // << "\ncontent of symbol table\n"
// // << std::endl;
// // interpreter.getCallStack().getGlobalScope()->print();
}
void printTokens(std::string input)
{
Lexer lexer{input};
for (auto token = lexer.getNextToken(); token.getTokenType() != Token::Type::END_OF_FILE; token = lexer.getNextToken())
std::cout << token << std::endl;
}
int main()
{
std::filesystem::path cwd = std::filesystem::current_path();
std::fstream file;
file.open(cwd / ".." / "program.txt", std::ios::in);
if (!file)
std::cout << "File not created!";
else
{
std::string content((std::istreambuf_iterator<char>(file)),
(std::istreambuf_iterator<char>()));
run(content);
file.close();
}
return 0;
}