From: John Hodge Date: Thu, 26 Aug 2010 13:45:53 +0000 (+0800) Subject: SpiderScript: Logical Functions, improved integer input X-Git-Tag: rel0.06~36 X-Git-Url: https://git.ucc.asn.au/?a=commitdiff_plain;h=55f3607e907b5dd82c5aa61cc289957619cac938;p=tpg%2Facess2.git SpiderScript: Logical Functions, improved integer input --- diff --git a/Usermode/Libraries/libspiderscript.so_src/lex.c b/Usermode/Libraries/libspiderscript.so_src/lex.c index 88437aa6..7121ce13 100644 --- a/Usermode/Libraries/libspiderscript.so_src/lex.c +++ b/Usermode/Libraries/libspiderscript.so_src/lex.c @@ -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; } diff --git a/Usermode/Libraries/libspiderscript.so_src/parse.c b/Usermode/Libraries/libspiderscript.so_src/parse.c index 6de82f7e..3e01bb14 100644 --- a/Usermode/Libraries/libspiderscript.so_src/parse.c +++ b/Usermode/Libraries/libspiderscript.so_src/parse.c @@ -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 ); }