-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
44 lines (40 loc) · 1.18 KB
/
main.cpp
File metadata and controls
44 lines (40 loc) · 1.18 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
#include <vector>
#include <string>
#include "token.hpp"
#include "lexer.hpp"
#include "parser.hpp"
#include "exception.cpp"
int main(int argc, char* argv[]) {
try {
std::string input;
if (argc > 1) {
input = argv[1];
}
else {
input = "f(x) = 3";
}
Lexer lexer(input);
std::vector<Token> tokens = lexer.tokenize();
Parser parser(tokens);
std::unique_ptr<ASTNode> ast = parser.parse_function();
ast->print();
} catch (const SyntaxError& e) {
std::cerr << e.what() << std::endl;
return 1;
} catch (const LexicalError& e) {
std::cerr << e.what() << std::endl;
return 1;
} catch (const RuntimeError& e) {
std::cerr << e.what() << std::endl;
return 1;
} catch (const InterpreterException& e) {
// Catches any interpreter exception not caught above
std::cerr << e.what() << std::endl;
return 1;
} catch (const std::exception& e) {
// Catches any other standard exception
std::cerr << "Unexpected error: " << e.what() << std::endl;
return 1;
}
return 0;
}