-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathnodes.h
97 lines (75 loc) · 1.93 KB
/
nodes.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#ifndef NODES_H
#define NODES_H
#include <string>
#include <memory>
namespace Math_Interpreter {
enum class NodeKind {
Number,
Add,
Subtract,
Multiply,
Divide,
Plus,
Minus
};
class Node {
public:
virtual NodeKind kind() const = 0;
virtual std::string str() const = 0;
virtual ~Node() = default;
};
class NumberNode : public Node {
public:
double value;
explicit NumberNode(double value);
NodeKind kind() const;
std::string str() const;
};
class AddNode : public Node {
public:
std::unique_ptr<Node> node_a;
std::unique_ptr<Node> node_b;
explicit AddNode(std::unique_ptr<Node> node_a, std::unique_ptr<Node> node_b);
NodeKind kind() const;
std::string str() const;
};
class SubtractNode : public Node {
public:
std::unique_ptr<Node> node_a;
std::unique_ptr<Node> node_b;
explicit SubtractNode(std::unique_ptr<Node> node_a, std::unique_ptr<Node> node_b);
NodeKind kind() const;
std::string str() const;
};
class MultiplyNode : public Node {
public:
std::unique_ptr<Node> node_a;
std::unique_ptr<Node> node_b;
explicit MultiplyNode(std::unique_ptr<Node> node_a, std::unique_ptr<Node> node_b);
NodeKind kind() const;
std::string str() const;
};
class DivideNode : public Node {
public:
std::unique_ptr<Node> node_a;
std::unique_ptr<Node> node_b;
explicit DivideNode(std::unique_ptr<Node> node_a, std::unique_ptr<Node> node_b);
NodeKind kind() const;
std::string str() const;
};
class PlusNode : public Node {
public:
std::unique_ptr<Node> node;
explicit PlusNode(std::unique_ptr<Node> node);
NodeKind kind() const;
std::string str() const;
};
class MinusNode : public Node {
public:
std::unique_ptr<Node> node;
explicit MinusNode(std::unique_ptr<Node> node);
NodeKind kind() const;
std::string str() const;
};
} // namespace Math_Interpreter
#endif // NODES_H