aboutsummaryrefslogtreecommitdiff
path: root/src/nodes.h
blob: 170b88f4a0aa254a7bbd69adfb5b212ca58ba1ba (plain)
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
#ifndef PARSER_SRC_NODES_H_
#define PARSER_SRC_NODES_H_

#include <map>
#include <string>

namespace SimpleParser {

enum class TokenType;
typedef std::map<std::string, double> ConstantMap;

enum class NodeType {
	OPERAND,
	OPERATOR,
	CONSTANT,
};

class Node {
	public:
		virtual ~Node() {};

		virtual double solve()      = 0;
		virtual NodeType getType()  = 0;
		virtual std::string print() = 0;
		
		Node* leftChild;
		Node* rightChild;
};

class OperatorNode: public Node {
	public:
		explicit OperatorNode(TokenType);

		virtual double solve();
		virtual NodeType getType();
		virtual std::string print();

		TokenType getToken();

	private:
		TokenType operator_;
};

class OperandNode: public Node {
	public:
		explicit OperandNode(double);

		virtual double solve();
		virtual NodeType getType();
		virtual std::string print();

	private:
		double value_;
};

class ConstantNode: public Node {
	public:
		explicit ConstantNode(std::string, const ConstantMap*);

		virtual double solve();
		virtual NodeType getType();
		virtual std::string print();

	private:
		std::string identifier_;
		const ConstantMap* constants_;
};

}

#endif  // PARSER_SRC_NODES_H_