aboutsummaryrefslogtreecommitdiff
path: root/src/nodes.h
blob: 9559722b5e92e3790ba2250579bb73a857ba3661 (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
#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;

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

		virtual double solve()      const = 0;
		virtual std::string print() const = 0;

		Node* leftChild;
		Node* rightChild;

};

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

		TokenType token() const;

		virtual double solve()      const;
		virtual std::string print() const;


	private:
		const TokenType operator_;

};

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

		virtual double solve()      const;
		virtual std::string print() const;

	private:
		const double value_;

};

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

		virtual double solve()      const;
		virtual std::string print() const;

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

};

}

#endif  // PARSER_SRC_NODES_H_