//===================================================================== // // ast.h: mini-C プログラムの抽象構文木 (ヘッダ) // // コンパイラ実習 2004 (c) 平岡佑介, 石浦菜岐佐 // //===================================================================== #ifndef INCLUDE_AST_H_ #define INCLUDE_AST_H_ #include #include #include //--------------------------------------------------------------------- // Type // 型 (int か char) を表す列挙型 //--------------------------------------------------------------------- enum Type { Type_INT, Type_CHAR }; //--------------------------------------------------------------------- // Type_string // Type の表示用文字列 //--------------------------------------------------------------------- std::string Type_string(Type t); //--------------------------------------------------------------------- // Operator // 演算子を表す列挙型 //--------------------------------------------------------------------- enum Operator{ Operator_PLUS, // + Operator_MINUS, // - Operator_MUL, // * Operator_DIV, // / Operator_MOD, // % Operator_LT, // < Operator_GT, // > Operator_LE, // <= Operator_GE, // >= Operator_NE, // != Operator_EQ, // == }; // static int tmp = 0; //--------------------------------------------------------------------- // Operator_string // Operator の表示用文字列 //--------------------------------------------------------------------- std::string Operator_string(Operator o); //--------------------------------------------------------------------- // class Expression // 「式」の抽象基底 //--------------------------------------------------------------------- class Expression { private: Expression(const Expression&); Expression& operator=(const Expression&); public: Expression() {} virtual ~Expression() {} virtual void print(std::ostream& os) const = 0; }; //--------------------------------------------------------------------- // class Exp_constant // 式中の定数を表す //--------------------------------------------------------------------- class Exp_constant : public Expression { private: Type type_; int value_; public: Exp_constant(Type t, int i) : type_(t), value_(i) {} ~Exp_constant() {} const int value() const {return value_;} const Type type() const {return type_;} void print(std::ostream& os) const; }; #endif // ifndef INCLUDE_AST_H_