-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcalculator.hpp
56 lines (37 loc) · 1.11 KB
/
calculator.hpp
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
#pragma once
#ifndef __CALCULATOR_H__
#define __CALCULATOR_H__
#include <string>
#include <vector>
#include <unordered_map>
#include "expression.hpp"
#include "token.hpp"
namespace math {
class Calculator {
public:
Calculator();
~Calculator();
void calculate();
inline bool sintax_error() { return m_syntaxError; }
private:
void reset();
void getStringExpression();
void tokenizeExpression();
void flushToken(Expression& arr, std::string& str);
void preparseExpression();
void parseExpression();
bool parseSigns(Expression& expr, int& i);
bool parseImplicitMultiplication(Expression& expr, int& i);
void processRPN();
void getResult(Expression& buf, int i);
void to_string(const Expression& expr);
void to_stringRPN(const Expression& expr);
std::vector<long double> m_results;
bool m_syntaxError;
std::string m_inputExpression;
std::vector<Expression> m_tokenExpressions;
std::vector<Expression> m_rpnExpressions;
std::unordered_map<const char*, long double> m_variables;
};
}
#endif // __CALCULATOR_H__