-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmyopl.cpp
46 lines (41 loc) · 1.14 KB
/
myopl.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
#include <iostream>
#include "include/lexer.hpp"
#include "include/token.hpp"
#include "include/errors.hpp"
#include "include/consts.hpp"
#include "include/parser.hpp"
#include "include/nodes.hpp"
tokenErrorPair run(std::string fn, std::string text){
Lexer lexer = Lexer(fn , text);
tokenErrorPair tokensAndError = lexer.makeTokens();
Parser parser = Parser(tokensAndError.tokens);
Node* ast = parser.parse();
std::cout << ast->asString() << std::endl;
return tokensAndError;
};
int shell() {
while (1) {
// Declare input and read
std::string inp;
std::cout << "basic> ";
std::getline(std::cin, inp);
// Create the lexer and pass the input
// Make a vector of the tokens
tokenErrorPair tokensAndError = run("<stdin>", inp);
if (tokensAndError.error.name != NULL_STR){
std::cerr << tokensAndError.error.asString() << std::endl;
continue;
} else {
// Loop through and print them
std::cout << "[";
for (int i = 0; i < tokensAndError.tokens.size(); i++) {
std::cout << tokensAndError.tokens[i].asString() << ", ";
};
std::cout << "]" << std::endl;
}
}
}
int main(int argc, char **argv) {
shell();
return 0;
}