// Token.h Dave Reed 9/30/03 // // Token class -- used to represent a token (language element) // Note: utilizes an enumerated type for the different token types // TOKEN_TYPE = STRING, INTEGER, IDENTIFIER, KEYWORD, OPERATOR, or UNKNOWN // // constructor: create a Token by specifying value and type // (if no arguments are specified, the default Token is UNKNOWN) // e.g., Token t("x1", IDENTIFIER); // Token u; // // public member functions: // string GetValue(); // returns the value of the token // void SetValue(string v); // set the value of the token // TOKEN_TYPE GetType(); // returns the type of the token // void SetType(TOKEN_TYPE t); // sets the type of the token ///////////////////////////////////////////////////////////////////////////////// #ifndef _TOKEN_ #define _TOKEN_ #include using namespace std; enum TOKEN_TYPE {STRING, INTEGER, IDENTIFIER, KEYWORD, OPERATOR, UNKNOWN}; class Token { public: Token(string v = "", TOKEN_TYPE t = UNKNOWN); string GetValue() const; void SetValue(string v); TOKEN_TYPE GetType() const; void SetType(TOKEN_TYPE t); private: string value; TOKEN_TYPE type; }; #endif