0
|
1 //
|
|
2 // ノードクラス
|
|
3 //
|
|
4 // Chihiro.SAKAMOTO
|
|
5 //
|
|
6 #ifndef __NODE_H__
|
|
7 #define __NODE_H__
|
|
8
|
|
9 #include <string>
|
|
10
|
|
11 // ノードの命令・トークン種別
|
|
12 enum {
|
|
13 OP_EOF = -1,
|
|
14 OP_NEG,
|
|
15 OP_PLUS,
|
|
16 OP_MINUS,
|
|
17 OP_TIMES,
|
|
18 OP_DIVIDE,
|
|
19 OP_VALUE,
|
|
20 OP_CONST,
|
|
21 OP_OPAR,
|
|
22 OP_CPAR,
|
|
23 OP_EQU,
|
|
24 OP_NEWLINE,
|
|
25 OP_PRINT,
|
|
26 OP_LIST,
|
|
27 OP_ERROR,
|
|
28 } ;
|
|
29
|
|
30 // ノード
|
|
31
|
|
32 class calc_driver;
|
|
33 class cnode {
|
|
34 public:
|
|
35 cnode(int op, cnode *left, cnode *right=0)
|
|
36 : op_(op), left_(left), right_(right), value_(0), string_(0)
|
|
37 {
|
|
38 }
|
|
39 cnode(int op, int value)
|
|
40 : op_(op), left_(0), right_(0), value_(value), string_(0)
|
|
41 {
|
|
42 }
|
|
43 cnode(int op, std::string *str)
|
|
44 : op_(op), left_(0), right_(0), value_(0), string_(str)
|
|
45 {
|
|
46 }
|
|
47 virtual ~cnode()
|
|
48 {
|
|
49 delete left_;
|
|
50 delete right_;
|
|
51 delete string_;
|
|
52 }
|
|
53
|
|
54 int expr(calc_driver *driver) const;
|
|
55
|
|
56 int op() const { return op_; }
|
|
57 int value() const { return value_; }
|
|
58 const std::string &string() const { return *string_; }
|
|
59 const cnode *left() const { return left_; }
|
|
60 const cnode *right() const { return right_; }
|
|
61
|
|
62 protected:
|
|
63 int op_;
|
|
64 int value_;
|
|
65 std::string *string_;
|
|
66 cnode *left_;
|
|
67 cnode *right_;
|
|
68 } ;
|
|
69
|
|
70 #endif
|