-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsymbolic.h
63 lines (53 loc) · 1.38 KB
/
symbolic.h
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
#include <string>
#include <vector>
#include <unordered_map>
#include <cstdint>
#include <boost/multiprecision/cpp_int.hpp>
using namespace boost::multiprecision;
class Symbol;
enum Op { ADD, SUB, MUL, DIV, AND, OR, XOR, NOT, UNDEFINED };
std::vector<std::string> op_strings = { "+", "-", "*", "/", "&", "|", "^", "!", "NOP" };
class Expression
{
public:
Expression();
Expression(const Symbol&);
Expression eval();
bool is_numeric() const;
std::string print();
Expression operator+(const Expression&);
Expression operator-(const Expression&);
Expression operator*(const Expression&);
Expression operator/(const Expression&);
Expression operator&(const Expression&);
Expression operator|(const Expression&);
Expression operator^(const Expression&);
Expression operator=(const Symbol&);
std::vector<Symbol> symbols;
Op op;
};
class Symbol
{
public:
Symbol();
Symbol(const Expression&);
Symbol(const std::string&);
Symbol(int128_t);
std::string print();
bool is_numeric() const;
// a symbol can be a numeric, a string or an expression
enum Type { NUMERIC, STRING, EXPRESSION, UNDEFINED } type;
int128_t value;
std::string name;
Expression expr;
};
class SymbolicEnv
{
public:
void add(const std::string&, const Symbol&);
void remove(const std::string&);
Symbol& operator[](const std::string& name);
void print();
private:
std::unordered_map<std::string, Symbol> env;
};