SpiderScript: Logical Functions, improved integer input
authorJohn Hodge <[email protected]>
Thu, 26 Aug 2010 13:45:53 +0000 (21:45 +0800)
committerJohn Hodge <[email protected]>
Thu, 26 Aug 2010 13:45:53 +0000 (21:45 +0800)
Usermode/Libraries/libspiderscript.so_src/lex.c
Usermode/Libraries/libspiderscript.so_src/parse.c

index 88437aa..7121ce1 100644 (file)
@@ -134,6 +134,33 @@ int GetToken(tParser *File)
        case '\0':      ret = TOK_EOF;  break;
        
        // Operations
+       case '^':
+               if( *File->CurPos == '^' ) {
+                       File->CurPos ++;
+                       ret = TOK_LOGICXOR;
+                       break;
+               }
+               ret = TOK_XOR;
+               break;
+       
+       case '|':
+               if( *File->CurPos == '|' ) {
+                       File->CurPos ++;
+                       ret = TOK_LOGICOR;
+                       break;
+               }
+               ret = TOK_OR;
+               break;
+       
+       case '&':
+               if( *File->CurPos == '&' ) {
+                       File->CurPos ++;
+                       ret = TOK_LOGICAND;
+                       break;
+               }
+               ret = TOK_AND;
+               break;
+       
        case '/':       ret = TOK_DIV;  break;
        case '*':       ret = TOK_MUL;  break;
        case '+':       ret = TOK_PLUS; break;
@@ -200,11 +227,23 @@ int GetToken(tParser *File)
        // Default (Numbers and Identifiers)
        default:
                File->CurPos --;
+               
                // Numbers
                if( isdigit(*File->CurPos) )
                {
-                       while( isdigit(*File->CurPos) )
-                               File->CurPos ++;
+                       if( *File->CurPos == '0' && File->CurPos[1] == 'x' ) {
+                               File->CurPos += 2;
+                               while(('0' <= *File->CurPos && *File->CurPos <= '9')
+                                  || ('A' <= *File->CurPos && *File->CurPos <= 'F')
+                                  || ('a' <= *File->CurPos && *File->CurPos <= 'f') )
+                               {
+                                       File->CurPos ++;
+                               }
+                       }
+                       else {
+                               while( isdigit(*File->CurPos) )
+                                       File->CurPos ++;
+                       }
                        ret = TOK_INTEGER;
                        break;
                }
index 6de82f7..3e01bb1 100644 (file)
@@ -561,9 +561,49 @@ tAST_Node *Parse_GetString(tParser *Parser)
  */
 tAST_Node *Parse_GetNumeric(tParser *Parser)
 {
-       uint64_t        value;
+       uint64_t        value = 0;
+       char    *pos;
        GetToken( Parser );
-       value = atoi( Parser->TokenStr );
+       pos = Parser->TokenStr;
+       //printf("pos = %p, *pos = %c\n", pos, *pos);
+               
+       if( *pos == '0' )
+       {
+               pos ++;
+               if(*pos == 'x') {
+                       pos ++;
+                       for( ;; pos++)
+                       {
+                               value *= 16;
+                               if( '0' <= *pos && *pos <= '9' ) {
+                                       value += *pos - '0';
+                                       continue;
+                               }
+                               if( 'A' <= *pos && *pos <= 'F' ) {
+                                       value += *pos - 'A' + 10;
+                                       continue;
+                               }
+                               if( 'a' <= *pos && *pos <= 'f' ) {
+                                       value += *pos - 'a' + 10;
+                                       continue;
+                               }
+                               break;
+                       }
+               }
+               else {
+                       while( '0' <= *pos && *pos <= '7' ) {
+                               value = value*8 + *pos - '0';
+                               pos ++;
+                       }
+               }
+       }
+       else {
+               while( '0' <= *pos && *pos <= '9' ) {
+                       value = value*10 + *pos - '0';
+                       pos ++;
+               }
+       }
+       
        return AST_NewInteger( Parser, value );
 }
 

UCC git Repository :: git.ucc.asn.au