-
Notifications
You must be signed in to change notification settings - Fork 0
/
Expression.hpp
77 lines (73 loc) · 2.03 KB
/
Expression.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#ifndef EXPRESSION_HPP
# define EXPRESSION_HPP
#include "utils.hpp"
#include "Symbol.hpp"
#include "Rational.hpp"
#include "Complex.hpp"
#include "Matrix.hpp"
#include "Computer.hpp"
class Expression
{
public:
class InvalidCharException : public exception
{
public:
InvalidCharException(string expr, int pos) : _pos(pos), _expr(expr) {}
virtual const char *what() const throw();
private:
int _pos;
string _expr;
};
class InvalidExpression : public exception
{
public:
InvalidExpression(int type, int tIdx, vector<string> const &tokens, int var1 = 0 , int var2 = 0);
virtual const char *what() const throw();
int _type;
private:
string _message;
};
class BadTokenException : public exception
{
public:
BadTokenException(string token) : _token(token) {}
virtual const char *what() const throw();
private:
string _token;
};
class BadParenthesisException : public exception
{
public:
virtual const char *what() const throw();
};
class BadBracketException : public exception
{
public:
virtual const char *what() const throw();
};
Expression();
Expression(vector<Symbol *> const &symbols);
Expression(string const &expr);
Expression(string const &expr, vector<string> vars);
Expression(Expression const &src);
~Expression();
vector<Symbol *> getSymbols() const;
Expression &operator=(Expression const &rhs);
bool validChar(char const c) const;
bool isOperator(char const c) const;
vector<string> breakDown(string const &token) const;
void toRPN();
Symbol *tokenToSymbol(string const &token);
Symbol *evaluate() const;
void print() const;
vector<Symbol *> _rpn;
vector<Symbol *> _symbols;
set<string> unkowns;
vector<string> placeHolders;
private:
static string validChars;
static string operators;
vector<string> _tokens;
};
ostream& operator<<(ostream &o,const Expression &rhs);
#endif