Mercurial > hg > Members > nobuyasu > SampleSource
comparison boost-spirit/CALC/closure/EUC/node.h @ 0:db40c85cad7a default tip
upload sample source
author | nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Mon, 09 May 2011 03:11:59 +0900 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:db40c85cad7a |
---|---|
1 #ifndef __NODE_H__ | |
2 #define __NODE_H__ | |
3 | |
4 #include <iostream> | |
5 #include <string> | |
6 #include <map> | |
7 #include <boost/shared_ptr.hpp> | |
8 | |
9 // ノード | |
10 | |
11 // ノードの命令 | |
12 enum OPCODE { | |
13 OP_NEG, | |
14 OP_PLUS, | |
15 OP_MINUS, | |
16 OP_TIMES, | |
17 OP_DIVIDE, | |
18 OP_NUMBER, | |
19 OP_IDENT, | |
20 } ; | |
21 | |
22 // ノード | |
23 | |
24 class cnode; | |
25 typedef boost::shared_ptr<cnode> cnode_t; | |
26 | |
27 class cnode { | |
28 public: | |
29 cnode(int op, const cnode_t &left, const cnode_t &right) | |
30 : op_(op), left_(left), right_(right), number_(0) | |
31 { | |
32 } | |
33 cnode(int op, const cnode_t &left) | |
34 : op_(op), left_(left), number_(0) | |
35 { | |
36 } | |
37 cnode(int op, int number) | |
38 : op_(op), number_(number) | |
39 { | |
40 } | |
41 cnode(int op, const std::string &str) | |
42 : op_(op), number_(0), string_(str) | |
43 { | |
44 } | |
45 cnode(int op, const char *b, const char *e) | |
46 : op_(op), string_(b, e) | |
47 { | |
48 } | |
49 | |
50 int expr(std::map<std::string, int> &values) const; | |
51 | |
52 int op() const { return op_; } | |
53 int number() const { return number_; } | |
54 const std::string &string() const { return string_; } | |
55 cnode_t left() const { return left_; } | |
56 cnode_t right() const { return right_; } | |
57 | |
58 protected: | |
59 int op_; | |
60 int number_; | |
61 std::string string_; | |
62 cnode_t left_; | |
63 cnode_t right_; | |
64 } ; | |
65 | |
66 #endif |