Changeset 119
- Timestamp:
- 01/06/08 03:23:19 (11 months ago)
- Files:
-
- branches/1.9/bin/walnut.exe (modified) (previous)
- branches/1.9/bin/walnut.lib (modified) (previous)
- branches/1.9/source/interpreter.d (modified) (5 diffs)
- branches/1.9/test/hello.nut (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/1.9/source/interpreter.d
r118 r119 4 4 text, 5 5 value; 6 7 private import 8 std.string; 6 9 7 10 uint line = 1; … … 23 26 c0 = c; 24 27 parseOperand(); 25 printf("%.*s",c0[0..(c-c0)]);28 // printf("%f",v.d); 26 29 } 27 30 … … 237 240 regular expressions (pass) 238 241 identifiers (pass) 239 numbers ( fail)242 numbers (all but e notation) 240 243 expressions (fail) 241 244 array literals (fail) … … 281 284 case '0': 282 285 if(c[1] == 'x') { 283 c+=2; 284 // parse a hexidecimal number 285 if(neg) 286 i = -1; 287 v.i = i; 288 v.type = TYPE.INT; 289 return; 286 c++; 287 do { 288 c++; 289 if(0x30 <= c[0] && c[0] <= 0x39) { 290 i <<= 4; 291 i += (c[0] - 0x30); 292 continue; 293 } 294 if(0x41 <= c[0] && c[0] <= 0x46) { 295 i <<= 4; 296 i += (c[0] - 0x37); 297 continue; 298 } 299 if(0x61 <= c[0] && c[0] <= 0x66) { 300 i <<= 4; 301 i += (c[0] - 0x57); 302 continue; 303 } 304 goto _endoct; 305 } while(1); 290 306 } 291 307 if(c[1] == '.') 292 308 goto _dec; 293 309 cMark = c; 294 // try parsing an octal number into i 295 // if(8 or 9) { 296 // c = cMark; 297 // goto _dec; } 310 do { 311 c++; 312 if(0x30 <= c[0] && c[0] <= 0x37) { 313 i <<= 3; 314 i += (c[0] - 0x30); 315 continue; 316 } 317 if(c[0] == 0x38 || c[0] == 0x39) { 318 c = cMark; 319 goto _dec; 320 } 321 break; 322 } while(1); 323 _endoct: 298 324 if(neg) 299 325 i = -i; … … 311 337 case '9': 312 338 _dec: 339 bool notInt; 340 double findex = 0.1; 341 342 d = c[0] - 0x30; 343 outer: do { 344 c++; 345 if(c[0] == '.') { 346 notInt = true; 347 do { 348 c++; 349 if(0x30 <= c[0] && c[0] <= 0x39) { 350 d += (c[0] - 0x30) * findex; 351 printf("%.*s\n",std.string.toString(d)); 352 findex *= 0.1; 353 continue; 354 } 355 break outer; 356 } while(1); 357 } 358 if(0x30 <= c[0] && c[0] <= 0x39) { 359 d *= 10; 360 d += c[0] - 0x30; 361 continue; 362 } 363 break; 364 } while(1); 365 313 366 // we have a decimal number. Build it in d 314 367 if(neg) 315 368 d = -d; 316 i = cast(int) d; 317 if(i == d) { 318 v.i = i; 319 v.type = TYPE.INT; 320 return; 321 } 322 v.d = d; 323 v.type = TYPE.DOUBLE; 369 if(notInt) { 370 v.d = d; 371 v.type = TYPE.DOUBLE; 372 return; 373 } 374 v.i = cast(int) d; 375 v.type = TYPE.INT; 324 376 return; 325 377 case '(': branches/1.9/test/hello.nut
r118 r119 1 1 2 2 3 423 0x12aC
