-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cpp
55 lines (46 loc) · 1.22 KB
/
Program.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
43
44
45
46
47
48
49
50
51
52
53
54
55
#include <iostream>
#include "Tokenizer.h"
#include "Token.h"
#include "Parser.h"
#include "Statement.h"
#include <string>
#include "Context.h"
#include "TypedValue.h"
#include "Expression.h"
int main()
{
GlobalContext context([&](std::string msg, int line, int col) {
std::cout << "RUNTIME ERROR: " << msg << " @line " << line << " @column " << col << std::endl;
});
std::string line;
getline(std::cin, line);
while (line != "quit")
{
int parseTimeError = 0;
Tokenizer tokenizer(line, [&](std::string msg, int line, int col) {
std::cout << "TOKENIZER ERROR: " << msg << " @line " << line << " @column " << col << std::endl;
parseTimeError++;
});
std::vector<Token*> tokens = tokenizer.tokenize();
/*for (Token* token : tokens)
{
std::cout << *token << std::endl;
}*/
Parser parser(tokens.cbegin(), [&](std::string msg, int line, int col) {
std::cout << "PARSER ERROR: " << msg << " @line " << line << " @column " << col << std::endl;
parseTimeError++;
});
Statement* stat;
while ((stat = parser.parseStatement()) != nullptr)
{
if (parseTimeError == 0) stat->run(context);
delete stat;
}
for (Token* token : tokens)
{
delete token;
}
getline(std::cin, line);
}
return 0;
}