50 public: |
50 public: |
51 Lexer(); |
51 Lexer(); |
52 ~Lexer(); |
52 ~Lexer(); |
53 |
53 |
54 void ProcessFile (String file_name); |
54 void ProcessFile (String file_name); |
55 bool GetNext (EToken req = tkAny); |
55 bool GetNext (TokenType req = TK_Any); |
56 void MustGetNext (EToken tok); |
56 void MustGetNext (TokenType tok); |
57 void MustGetAnyOf (const List<EToken>& toks); |
57 void MustGetAnyOf (const List<TokenType>& toks); |
58 int GEXPRSYM_tOne (const StringList& syms); |
58 int GetOneSymbol (const StringList& syms); |
59 void TokenMustBe (EToken tok); |
59 void TokenMustBe (TokenType tok); |
60 bool PeekNext (Token* tk = null); |
60 bool PeekNext (Token* tk = null); |
61 bool PeekNextType (EToken req); |
61 bool PeekNextType (TokenType req); |
62 String PeekNextString (int a = 1); |
62 String PeekNextString (int a = 1); |
63 String DescribeCurrentPosition(); |
63 String DescribeCurrentPosition(); |
64 String DescribeTokenPosition(); |
64 String DescribeTokenPosition(); |
65 |
65 |
66 static Lexer* GetCurrentLexer(); |
66 static Lexer* GetCurrentLexer(); |
79 inline bool IsAtEnd() const |
79 inline bool IsAtEnd() const |
80 { |
80 { |
81 return mTokenPosition == mTokens.end(); |
81 return mTokenPosition == mTokens.end(); |
82 } |
82 } |
83 |
83 |
84 inline EToken GetTokenType() const |
84 inline TokenType GetTokenType() const |
85 { |
85 { |
86 return GetToken()->type; |
86 return GetToken()->type; |
87 } |
87 } |
88 |
88 |
89 inline void Skip (int a = 1) |
89 inline void Skip (int a = 1) |
100 { |
100 { |
101 mTokenPosition = mTokens.begin() + pos; |
101 mTokenPosition = mTokens.begin() + pos; |
102 } |
102 } |
103 |
103 |
104 // If @tok is given, describes the token. If not, describes @tok_type. |
104 // If @tok is given, describes the token. If not, describes @tok_type. |
105 static inline String DescribeTokenType (EToken toktype) |
105 static inline String DescribeTokenType (TokenType toktype) |
106 { |
106 { |
107 return DescribeTokenPrivate (toktype, null); |
107 return DescribeTokenPrivate (toktype, null); |
108 } |
108 } |
109 |
109 |
110 static inline String DescribeToken (Token* tok) |
110 static inline String DescribeToken (Token* tok) |
115 private: |
115 private: |
116 TokenList mTokens; |
116 TokenList mTokens; |
117 Iterator mTokenPosition; |
117 Iterator mTokenPosition; |
118 |
118 |
119 // read a mandatory token from scanner |
119 // read a mandatory token from scanner |
120 void MustGetFromScanner (LexerScanner& sc, EToken tt = tkAny); |
120 void MustGetFromScanner (LexerScanner& sc, TokenType tt =TK_Any); |
121 void CheckFileHeader (LexerScanner& sc); |
121 void CheckFileHeader (LexerScanner& sc); |
122 |
122 |
123 static String DescribeTokenPrivate (EToken tok_type, Token* tok); |
123 static String DescribeTokenPrivate (TokenType tok_type, Token* tok); |
124 }; |
124 }; |
125 |
125 |
126 #endif // BOTC_LEXER_H |
126 #endif // BOTC_LEXER_H |