Mercurial > hg > Members > nobuyasu > SampleSource
view Bison-Flex/CALC/discrete-parser/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 |
line wrap: on
line source
// // ノードクラス // // Chihiro.SAKAMOTO // #ifndef __NODE_H__ #define __NODE_H__ #include <string> // ノードの命令・トークン種別 enum { OP_EOF = -1, OP_NEG, OP_PLUS, OP_MINUS, OP_TIMES, OP_DIVIDE, OP_VALUE, OP_CONST, OP_OPAR, OP_CPAR, OP_EQU, OP_NEWLINE, OP_PRINT, OP_LIST, OP_ERROR, } ; // ノード class calc_driver; class cnode { public: cnode(int op, cnode *left, cnode *right=0) : op_(op), left_(left), right_(right), value_(0), string_(0) { } cnode(int op, int value) : op_(op), left_(0), right_(0), value_(value), string_(0) { } cnode(int op, std::string *str) : op_(op), left_(0), right_(0), value_(0), string_(str) { } virtual ~cnode() { delete left_; delete right_; delete string_; } int expr(calc_driver *driver) const; int op() const { return op_; } int value() const { return value_; } const std::string &string() const { return *string_; } const cnode *left() const { return left_; } const cnode *right() const { return right_; } protected: int op_; int value_; std::string *string_; cnode *left_; cnode *right_; } ; #endif