comparison trunk/src/dil/Lexer.d @ 396:0a4619735ce9

Applied fixes to Lexer, Parser and other classes. Added asserts to cmd.Generate.syntaxToDoc(). Added if-statements to Declaration, Expression and Statement classes to check for null variables. Fixed octal number scanner in Lexer.scanNumber(). Fixes in Parser: skip comma in parseBaseClasses(); changed || to &&; added 'qword' to list of asm type prefixes.
author Aziz K?ksal <aziz.koeksal@gmail.com>
date Fri, 21 Sep 2007 12:47:47 +0200
parents fce1e6133dac
children c99f8aeb7b4a
comparison
equal deleted inserted replaced
395:ac9cd48151b6 396:0a4619735ce9
1333 switch (*p) 1333 switch (*p)
1334 { 1334 {
1335 case 'x','X': 1335 case 'x','X':
1336 goto LscanHex; 1336 goto LscanHex;
1337 case 'b','B': 1337 case 'b','B':
1338 goto LscanBin; 1338 goto LscanBinary;
1339 case 'L': 1339 case 'L':
1340 if (p[1] == 'i') 1340 if (p[1] == 'i')
1341 goto LscanReal; 1341 goto LscanReal; // 0Li
1342 break; 1342 break; // 0L
1343 case '.': 1343 case '.':
1344 if (p[1] == '.') 1344 if (p[1] == '.')
1345 break; 1345 break; // 0..
1346 // 0.
1346 case 'i','f','F', // Imaginary and float literal suffixes. 1347 case 'i','f','F', // Imaginary and float literal suffixes.
1347 'e', 'E': // Float exponent. 1348 'e', 'E': // Float exponent.
1348 goto LscanReal; 1349 goto LscanReal;
1349 default: 1350 default:
1350 if (*p == '_' || isoctal(*p)) 1351 if (*p == '_')
1351 goto LscanOct; 1352 goto LscanOctal; // 0_
1353 else if (isdigit(*p))
1354 {
1355 if (*p == '8' || *p == '9')
1356 goto Loctal_hasDecimalDigits; // 08 or 09
1357 else
1358 goto Loctal_enter_loop; // 0[0-7]
1359 }
1352 } 1360 }
1353 1361
1354 // Number 0 1362 // Number 0
1355 assert(p[-1] == '0'); 1363 assert(p[-1] == '0');
1364 assert(*p != '_' && !isdigit(*p));
1356 assert(ulong_ == 0); 1365 assert(ulong_ == 0);
1357 isDecimal = true; 1366 isDecimal = true;
1358 goto Lfinalize; 1367 goto Lfinalize;
1359 1368
1360 LscanInteger: 1369 LscanInteger:
1438 else if (digits > 16) 1447 else if (digits > 16)
1439 error(MID.OverflowHexNumber); 1448 error(MID.OverflowHexNumber);
1440 1449
1441 goto Lfinalize; 1450 goto Lfinalize;
1442 1451
1443 LscanBin: 1452 LscanBinary:
1444 assert(digits == 0); 1453 assert(digits == 0);
1445 assert(*p == 'b'); 1454 assert(*p == 'b');
1446 while (1) 1455 while (1)
1447 { 1456 {
1448 if (*++p == '0') 1457 if (*++p == '0')
1469 1478
1470 assert(p[-1] == '0' || p[-1] == '1' || p[-1] == '_', p[-1] ~ ""); 1479 assert(p[-1] == '0' || p[-1] == '1' || p[-1] == '_', p[-1] ~ "");
1471 assert( !(*p == '0' || *p == '1' || *p == '_') ); 1480 assert( !(*p == '0' || *p == '1' || *p == '_') );
1472 goto Lfinalize; 1481 goto Lfinalize;
1473 1482
1474 LscanOct: 1483 LscanOctal:
1475 assert(*p == '_' || isoctal(*p)); 1484 assert(*p == '_');
1476 if (*p != '_')
1477 goto Lenter_loop_oct;
1478 while (1) 1485 while (1)
1479 { 1486 {
1480 if (*++p == '_') 1487 if (*++p == '_')
1481 continue; 1488 continue;
1482 if (!isoctal(*p)) 1489 if (!isoctal(*p))
1483 break; 1490 break;
1484 Lenter_loop_oct: 1491 Loctal_enter_loop:
1485 if (ulong_ < ulong.max/2 || (ulong_ == ulong.max/2 && *p <= '1')) 1492 if (ulong_ < ulong.max/2 || (ulong_ == ulong.max/2 && *p <= '1'))
1486 { 1493 {
1487 ulong_ *= 8; 1494 ulong_ *= 8;
1488 ulong_ += *p - '0'; 1495 ulong_ += *p - '0';
1489 ++p;
1490 continue; 1496 continue;
1491 } 1497 }
1492 // Overflow: skip following digits. 1498 // Overflow: skip following digits.
1493 overflow = true; 1499 overflow = true;
1494 while (isdigit(*++p)) {} 1500 while (isoctal(*++p)) {}
1495 break; 1501 break;
1496 } 1502 }
1497 1503
1498 bool hasDecimalDigits; 1504 bool hasDecimalDigits;
1499 if (isdigit(*p)) 1505 if (isdigit(*p))
1500 { 1506 {
1507 Loctal_hasDecimalDigits:
1501 hasDecimalDigits = true; 1508 hasDecimalDigits = true;
1502 while (isdigit(*++p)) {} 1509 while (isdigit(*++p)) {}
1503 } 1510 }
1504 1511
1505 // The number could be a float, so check errors below. 1512 // The number could be a float, so check errors below.