My Project
 All Classes Namespaces Functions Pages
token.h
1 #ifndef TOKEN_H
2 #define TOKEN_H
3 
4 #include <string>
5 #include <iostream>
6 #include <iomanip>
7 #include <map>
8 
9 void testToken();//NOTE: Because this file has implementation .cpp,
10  // The implementation need to be separated
11 
12 using namespace std;
13 
14 enum TokenType {
15  UNKNOWN = -1,
16  NONE = 0,
17  WHITESPACE = 1,
18  EOL = 2,
19  ALPHA = 3,
20  NUM = 4,
21  OPERATOR = 5,
22  PUNC = 6,
23  MATCHED = 7,
24  QUESTION
25 };
26 //bool operator == (const TokenType& l, const TokenType& r) { return l == r; }
27 
28 static map<TokenType, string> TokenName = {
29  {UNKNOWN, "UNKNOWN"},
30  {NONE, "NONE"},
31  {WHITESPACE, "WHITESPACE"},
32  {EOL, "EOL"},
33  {ALPHA, "ALPHA"},
34  {NUM, "NUM"},
35  {OPERATOR, "OPERATOR"},
36  {PUNC, "PUNC"},
37  {MATCHED, "MATCHED"},
38  {QUESTION, "QUESTION"}
39 };
40 
41 class Token
42 {
43  protected:
44  string mTokenString;
45  TokenType mType;
46 
47  public:
48  Token();
49  Token(const Token& other);
50  Token(string s, TokenType type);
51  Token(char ch, TokenType type);
52  TokenType getType() const;
53  string getTokenString() const;
54 
55  Token& operator = (const Token& newToken);
56  const string& operator * ();
57  friend ostream& operator << (ostream& outs, const Token& t)
58  {
59  outs << left << setw(10) << t.mTokenString << ": " << TokenName[t.mType];
60  return outs;
61  }
62 
63  ~Token();
64 };
65 
66 #endif // TOKEN_H
Definition: token.h:41