-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
58 lines (48 loc) · 1.18 KB
/
main.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
56
57
58
#include <iostream>
#include <sstream>
#include <string>
#include "lexer.h"
#include "parser.h"
#include "interpreter.h"
#include "astnode.h"
/*
* Example of an test function:
*
double test(const std::string &string) {
std::stringstream stream(string);
Lexer lexer(stream);
Parser parser(lexer);
Interpreter interpreter;
auto node = parser.parse();
return interpreter.interpret(*node);
}
*/
int main()
{
std::stringstream stream;
std::string input;
int length = 0;
while (std::cin >> input) {
stream << input;
length += input.size();
}
if (length == 0) {
std::cout
<< "Input empty. Provide input on the standard input like: echo \"2+2\" | Parser"
<< std::endl;
return 0;
}
try {
Lexer lexer(stream);
Parser parser(lexer);
Interpreter interpreter;
auto node = parser.parse();
std::cout << interpreter.interpret(*node) << std::endl;
delete node;
} catch (char const *reason) {
std::cerr << reason << std::endl;
} catch (...) {
std::cerr << "Something realy wrong happened." << std::endl;
}
return 0;
}