diff options
author | Mike Buland <mike@xagasoft.com> | 2013-05-08 13:36:09 -0600 |
---|---|---|
committer | Mike Buland <mike@xagasoft.com> | 2013-05-08 13:36:09 -0600 |
commit | fc14c0f16e881607e55f04516934818091331bd3 (patch) | |
tree | a104a99bfec86501f7b71151004924f48cadaa6d /src/lexer.cpp | |
parent | 69d9a257ba02c973da5708d9b6055e4ac5dc0ee2 (diff) | |
download | clic-fc14c0f16e881607e55f04516934818091331bd3.tar.gz clic-fc14c0f16e881607e55f04516934818091331bd3.tar.bz2 clic-fc14c0f16e881607e55f04516934818091331bd3.tar.xz clic-fc14c0f16e881607e55f04516934818091331bd3.zip |
Command parameters are taken as strings & decimal.0.06
You no longer need to set the radix in the current radix.
Diffstat (limited to 'src/lexer.cpp')
-rw-r--r-- | src/lexer.cpp | 68 |
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 | ||
21 | Token Lexer::nextToken() | 22 | Token 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 | |||
37 | Token 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 | ||
170 | Token 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 | |||
154 | void Lexer::setRadix( int i ) | 220 | void Lexer::setRadix( int i ) |
155 | { | 221 | { |
156 | iRadix = i; | 222 | iRadix = i; |