#ifndef _EXPRESSION_H_ #define _EXPRESSION_H_ #include #include #include "gpl_type.h" #include #include "error.h" // note - remember to add the garbage collector /* * This abstract class is parent of all the various expression classes. */ // #define PI 3.141592653 #define radians(x) ((x)*PI/180) #define degrees(x) ((x)*180/PI) #define OP_ADD 0x01 #define OP_SUB 0x02 #define OP_DIV 0x03 #define OP_MUL 0x04 #define OP_MOD 0x05 #define OP_AND 0x06 #define OP_OR 0x07 #define OP_EQU 0x08 #define OP_GR 0x09 #define OP_GEQ 0x0A #define OP_LE 0x0B #define OP_LEQ 0x0C #define OP_NEQ 0x0D #define OP_NEG 0x0E #define OP_NOT 0x0F #define MATH_SIN 0x11 #define MATH_COS 0x12 #define MATH_TAN 0x13 #define MATH_ASIN 0x14 #define MATH_ACOS 0x15 #define MATH_ATAN 0x16 #define MATH_SQRT 0x17 #define MATH_ABS 0x18 #define MATH_FLOOR 0x19 #define MATH_RANDOM 0x1A #define OP_TOUCHES 0x21 #define OP_NEAR 0x22 class Expression { public: int my_type; int line; // which line is it on? // Functions for getting the value: // If not overloaded these should be a type error. virtual double as_float(void) = 0; virtual string *as_string(void) = 0; virtual long as_int(void) = 0; virtual int type(void) = 0; int type_check(int op, int ltype, int rtype); virtual ~Expression() {}; double int_to_double(long in); string *int_to_string(long in); string *double_to_string(double in); }; class OperatorExpr: public Expression { public: int op; virtual double as_float(void) = 0; virtual string *as_string(void) = 0; virtual long as_int(void) = 0; }; class UnaryExpr: public OperatorExpr { public: UnaryExpr(int op, Expression *operand) ; int type(void) {return my_type;}; double as_float(void); string *as_string(void); long as_int(void); Expression *operand; }; class BinaryExpr: public OperatorExpr { public: BinaryExpr(int op, Expression *left, Expression *right); double as_float(void); string *as_string(void); long as_int(void); int type(void) {return my_type;}; Expression *left_operand, *right_operand; }; class MathExpr: public OperatorExpr { public: MathExpr(int op, Expression *operand); double as_float(void); string *as_string(void); int type(void) {return my_type;}; long as_int(void); // = MATH_SIN or whatever Expression *operand; }; class VariableExpr: public Expression { public: VariableExpr(string *tid, string *atr, Expression *index); long as_int(void); string *as_string(void); double as_float(void); Expression *index; int type(void); string *name; string *member; }; class PrimaryExpr: public Expression { public: }; class IntConstantExpr: public PrimaryExpr { public: IntConstantExpr(long value) {this->value = value; }; long value; int type(void) {return TYPE_INT;}; double as_float(void); string *as_string(void); long as_int(void); }; class StringConstantExpr: public PrimaryExpr { public: StringConstantExpr(string *value) {this->value = value; }; string *value; double as_float(void); int type(void) {return TYPE_STRING;}; string *as_string(void); long as_int(void); }; class FloatConstantExpr: public PrimaryExpr { public: FloatConstantExpr(double value) {this->value = value; }; double value; int type(void) {return TYPE_DOUBLE;}; double as_float(void); string *as_string(void); long as_int(void); }; class GeometricExpr: public OperatorExpr { public: ; }; class InitalizerExpr: public Expression { public: Expression *value; }; #endif