-
Notifications
You must be signed in to change notification settings - Fork 1
/
arithmetic.cpp
47 lines (37 loc) · 1.01 KB
/
arithmetic.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 "lib/Parser.hpp"
#include "lib/ShuntingYard.hpp"
#include "lib/PostfixEvaluation.hpp"
int main(int argc, char *argv[])
{
std::string line; // Input line
std::stack<std::string> output; // Output for the ShuntingYard algorithm
getline(std::cin, line); // Reading line and initialising ShuntingYard
// Parsing process
ShuntingYard sy(line);
try
{
sy.parsing();
}
catch (const std::invalid_argument &e)
{
std::cerr << "Error: " << e.what() << std::endl;
return 0;
}
//// Print output from ShuntingYard in RPN
//sy.print_result();
// Evaluation process
PostfixEvaluation pe;
try
{
//// RPN Evaluation
//std::cout << pe.rpn_evaluation(sy.get_rpn()) <<std::endl;
// AST Evaluation
std::cout << pe.ast_evaluation(sy.get_ast()) << std::endl;
}
catch (const std::invalid_argument &e)
{
std::cerr << "Error: " << e.what() << std::endl;
return 0;
}
return 0;
}