Changeset 119

Show
Ignore:
Timestamp:
01/06/08 03:23:19 (11 months ago)
Author:
dan.lewis
Message:

Interpreter now handles numbers except for e notation.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/1.9/source/interpreter.d

    r118 r119  
    44    text, 
    55    value; 
     6 
     7private import 
     8    std.string; 
    69 
    710uint line = 1; 
     
    2326    c0 = c; 
    2427    parseOperand(); 
    25    printf("%.*s",c0[0..(c-c0)]); 
     28// printf("%f",v.d); 
    2629} 
    2730 
     
    237240        regular expressions (pass) 
    238241        identifiers (pass) 
    239         numbers (fail
     242        numbers (all but e notation
    240243        expressions (fail) 
    241244        array literals (fail) 
     
    281284        case '0': 
    282285            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); 
    290306            } 
    291307            if(c[1] == '.') 
    292308                goto _dec; 
    293309            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: 
    298324            if(neg) 
    299325                i = -i; 
     
    311337        case '9': 
    312338            _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             
    313366            // we have a decimal number.  Build it in d 
    314367            if(neg) 
    315368                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; 
    324376            return; 
    325377        case '(': 
  • branches/1.9/test/hello.nut

    r118 r119  
    11 
    22 
    3    42 
     3   0x12aC