00001 #ifndef TOKEN_H 00002 #define TOKEN_H 00003 00004 #include "SundanceDefs.h" 00005 00006 #include <string> 00007 #include <iostream> 00008 00009 namespace Sundance 00010 { 00011 00012 using namespace TSF; 00013 using std::string; 00014 00015 using std::ostream; 00016 00017 00018 enum TokenType {TT_Unknown, TT_Assign, TT_OpenParen, TT_CloseParen, 00019 TT_OpenBracket, TT_CloseBracket, TT_OpenBrace, 00020 TT_CloseBrace, TT_Comma, TT_Plus, TT_Minus, TT_Times, 00021 TT_Divide, TT_Constant, TT_Name, TT_Equal, 00022 TT_LessThan, TT_GreaterThan, TT_LessThanOrEqual, 00023 TT_GreaterThanOrEqual, TT_And, TT_Or, 00024 TT_Not, TT_NotEqual, TT_End}; 00025 00026 class Token 00027 { 00028 public: 00029 Token() : tok_(), type_(TT_Unknown) {;} 00030 Token(const string& tok); 00031 00032 bool isUnknown() const {return type_==TT_Unknown;} 00033 00034 bool isAssign() const {return type_==TT_Assign;} 00035 bool isOpenParen() const {return type_==TT_OpenParen;} 00036 bool isCloseParen() const {return type_==TT_CloseParen;} 00037 bool isOpenBrace() const {return type_==TT_OpenBrace;} 00038 bool isCloseBrace() const {return type_==TT_CloseBrace;} 00039 bool isOpenBracket() const {return type_==TT_OpenBracket;} 00040 bool isCloseBracket() const {return type_==TT_CloseBracket;} 00041 bool isComma() const {return type_==TT_Comma;} 00042 00043 bool isPlus() const {return type_==TT_Plus;} 00044 bool isMinus() const {return type_==TT_Minus;} 00045 bool isTimes() const {return type_==TT_Times;} 00046 bool isDivide() const {return type_==TT_Divide;} 00047 00048 bool isConstant() const {return type_==TT_Constant;} 00049 bool isName() const {return type_==TT_Name;} 00050 00051 bool isEquality() const {return type_==TT_Equal;} 00052 bool isLessThan() const {return type_==TT_LessThan;} 00053 bool isGreaterThan() const {return type_==TT_GreaterThan;} 00054 bool isLessThanOrEqual() const {return type_==TT_LessThanOrEqual;} 00055 bool isGreaterThanOrEqual() const {return type_==TT_GreaterThanOrEqual;} 00056 bool isAnd() const {return type_==TT_And;} 00057 bool isOr() const {return type_==TT_Or;} 00058 bool isNot() const {return type_==TT_Not;} 00059 bool isNotEqual() const {return type_==TT_NotEqual;} 00060 00061 bool isEnd() const {return type_==TT_End;} 00062 00063 double value() const ; 00064 const string& name() const ; 00065 00066 const string& tok() const {return tok_;} 00067 void print(ostream& os) const {os << tok_;} 00068 private: 00069 string tok_; 00070 TokenType type_; 00071 }; 00072 00073 inline ostream& operator<<(ostream& os, const Token& t) 00074 { 00075 t.print(os); 00076 return os; 00077 } 00078 00079 } 00080 #endif