src/Lexer.h

changeset 115
9be16e1c1e44
parent 112
def56932f938
child 116
56ff19947607
equal deleted inserted replaced
114:6cbeb9f8350f 115:9be16e1c1e44
49 49
50 public: 50 public:
51 Lexer(); 51 Lexer();
52 ~Lexer(); 52 ~Lexer();
53 53
54 void ProcessFile (String file_name); 54 void processFile (String fileName);
55 bool Next (ETokenType req = TK_Any); 55 bool next (ETokenType req = TK_Any);
56 void MustGetNext (ETokenType tok); 56 void mustGetNext (ETokenType tok);
57 void MustGetAnyOf (const List<ETokenType>& toks); 57 void mustGetAnyOf (const List<ETokenType>& toks);
58 int GetOneSymbol (const StringList& syms); 58 int getOneSymbol (const StringList& syms);
59 void TokenMustBe (ETokenType tok); 59 void tokenMustBe (ETokenType tok);
60 bool PeekNext (TokenInfo* tk = null); 60 bool peekNext (TokenInfo* tk = null);
61 bool PeekNextType (ETokenType req); 61 bool peekNextType (ETokenType 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();
67 67
68 inline bool HasValidToken() const 68 inline bool hasValidToken() const
69 { 69 {
70 return (mTokenPosition < mTokens.end() && mTokenPosition >= mTokens.begin()); 70 return (m_tokenPosition < m_tokens.end() && m_tokenPosition >= m_tokens.begin());
71 } 71 }
72 72
73 inline TokenInfo* Token() const 73 inline TokenInfo* token() const
74 { 74 {
75 assert (HasValidToken() == true); 75 assert (hasValidToken() == true);
76 return &(*mTokenPosition); 76 return &(*m_tokenPosition);
77 } 77 }
78 78
79 inline bool IsAtEnd() const 79 inline bool isAtEnd() const
80 { 80 {
81 return mTokenPosition == mTokens.end(); 81 return m_tokenPosition == m_tokens.end();
82 } 82 }
83 83
84 inline ETokenType TokenType() const 84 inline ETokenType tokenType() const
85 { 85 {
86 return Token()->type; 86 return token()->type;
87 } 87 }
88 88
89 inline void Skip (int a = 1) 89 inline void skip (int a = 1)
90 { 90 {
91 mTokenPosition += a; 91 m_tokenPosition += a;
92 } 92 }
93 93
94 inline int Position() 94 inline int position()
95 { 95 {
96 return mTokenPosition - mTokens.begin(); 96 return m_tokenPosition - m_tokens.begin();
97 } 97 }
98 98
99 inline void SetPosition (int pos) 99 inline void setPosition (int pos)
100 { 100 {
101 mTokenPosition = mTokens.begin() + pos; 101 m_tokenPosition = m_tokens.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 (ETokenType toktype) 105 static inline String describeTokenType (ETokenType toktype)
106 { 106 {
107 return DescribeTokenPrivate (toktype, null); 107 return describeTokenPrivate (toktype, null);
108 } 108 }
109 109
110 static inline String DescribeToken (TokenInfo* tok) 110 static inline String describeToken (TokenInfo* tok)
111 { 111 {
112 return DescribeTokenPrivate (tok->type, tok); 112 return describeTokenPrivate (tok->type, tok);
113 } 113 }
114 114
115 private: 115 private:
116 TokenList mTokens; 116 TokenList m_tokens;
117 Iterator mTokenPosition; 117 Iterator m_tokenPosition;
118 118
119 // read a mandatory token from scanner 119 // read a mandatory token from scanner
120 void MustGetFromScanner (LexerScanner& sc, ETokenType tt =TK_Any); 120 void mustGetFromScanner (LexerScanner& sc, ETokenType tt =TK_Any);
121 void CheckFileHeader (LexerScanner& sc); 121 void checkFileHeader (LexerScanner& sc);
122 122
123 static String DescribeTokenPrivate (ETokenType tok_type, TokenInfo* tok); 123 static String describeTokenPrivate (ETokenType tok_type, TokenInfo* tok);
124 }; 124 };
125 125
126 #endif // BOTC_LEXER_H 126 #endif // BOTC_LEXER_H

mercurial