summaryrefslogtreecommitdiff
path: root/src/lexer.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/lexer.cpp')
-rw-r--r--src/lexer.cpp68
1 files changed, 67 insertions, 1 deletions
diff --git a/src/lexer.cpp b/src/lexer.cpp
index 2521b40..97ceb1b 100644
--- a/src/lexer.cpp
+++ b/src/lexer.cpp
@@ -10,7 +10,8 @@ Lexer::Lexer( Bu::Stream &rIn ) :
10 iScale( 0 ), 10 iScale( 0 ),
11 iRadix( 10 ), 11 iRadix( 10 ),
12 numRangeTop('9'), 12 numRangeTop('9'),
13 ascRangeTop('a'-1) 13 ascRangeTop('a'-1),
14 eMode( modeNormal )
14{ 15{
15} 16}
16 17
@@ -20,6 +21,21 @@ Lexer::~Lexer()
20 21
21Token Lexer::nextToken() 22Token Lexer::nextToken()
22{ 23{
24 switch( eMode )
25 {
26 case modeNormal:
27 return nextTokenNormal();
28
29 case modeCommand:
30 return nextTokenCommand();
31
32 default:
33 throw Bu::ExceptionBase("Invalid mode.");
34 }
35}
36
37Token Lexer::nextTokenNormal()
38{
23 for(;;) 39 for(;;)
24 { 40 {
25 if( iBufPos >= sBuf.getSize() ) 41 if( iBufPos >= sBuf.getSize() )
@@ -151,6 +167,56 @@ Token Lexer::nextToken()
151 } 167 }
152} 168}
153 169
170Token Lexer::nextTokenCommand()
171{
172 for(;;)
173 {
174 if( iBufPos >= sBuf.getSize() )
175 {
176 iBufPos = -1;
177 return Token( Token::tEndOfLine );
178 }
179
180 if( iBufPos < 0 )
181 {
182 if( rIn.isEos() )
183 return Token( Token::tEndOfInput );
184
185 sBuf = rIn.readLine();
186 if( sBuf.getSize() == 0 )
187 {
188 iBufPos = -1;
189 continue;
190 }
191 iBufPos = 0;
192 }
193
194 //Bu::println("Testing char '%1' at %2").arg( sBuf[iBufPos] ).arg( iBufPos );
195 switch( sBuf[iBufPos] )
196 {
197 case ' ':
198 case '\t':
199 iBufPos++;
200 break;
201
202 default:
203 {
204 Bu::String *sTmp = new Bu::String();
205 for( ; iBufPos < sBuf.getSize() ; iBufPos++ )
206 {
207 if( sBuf[iBufPos] == ' ' ||
208 sBuf[iBufPos] == '\t' )
209 break;
210
211 sTmp->append( sBuf[iBufPos] );
212 }
213 return Token( Token::tString, sTmp );
214 }
215 break;
216 }
217 }
218}
219
154void Lexer::setRadix( int i ) 220void Lexer::setRadix( int i )
155{ 221{
156 iRadix = i; 222 iRadix = i;