-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCompilador.cpp
More file actions
62 lines (46 loc) · 1.24 KB
/
Compilador.cpp
File metadata and controls
62 lines (46 loc) · 1.24 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
62
#include <iostream>
#include <string>
#include "reader/reader.cpp"
#include "parser/parser.cpp"
#include "token/token.cpp"
#ifndef COMPILER
#define COMPILER
class Compilador
{
public:
void compile_from_file() {
auto fileName = get_user_input();
auto lines_read = read_from_file(fileName);
std::cout << "+-----------------------------------------------+\n";
std::vector<Token*> tokens;
for (std::string line : lines_read)
tokens.push_back(parseExpression(line));
for (auto token : tokens) {
token->eval_to_str();
delete token;
}
std::cout << "+-----------------------------------------------+\n";
std::cout<<"Press ENTER to exit";
std::cin.ignore().get();
}
void live_repl() {
std::cout << "+-----------------------------------------------+\n";
std::cout << "| jarara v1.0 |\n";
std::cout << "+-----------------------------------------------+\n";
std::string line;
Token* token;
while(true) {
std::cout << ">>> ";
std::cin >> line;
if (line == "end<>") break;
try {
token = parseExpression(line);
std::cout << token->eval_to_str() << "\n";
delete token;
} catch (std::exception& e) {
std::cout << "comando invalido\n";
}
}
}
};
#endif