Beispiel #1
0
const char *PP_ScanToken( const char *p, ppt_token *token )
{
    const char  *p2;
    bool        white_space;
    ppt_token   ctoken;

    if( PPFlags & PPFLAG_SKIP_COMMENT ) {
        *token = PPT_COMMENT;
        for( ; *p != '\0'; ++p ) {
            if( p[0] == '*' && p[1] == '/' ) {
                p += 2;
                PPFlags &= ~PPFLAG_SKIP_COMMENT;
                break;
            }
        }
        return( p );
    }
    switch( *p ) {
    case '(':
        ++p;
        ctoken = PPT_LEFT_PAREN;
        break;
    case ')':
        ++p;
        ctoken = PPT_RIGHT_PAREN;
        break;
    case ',':
        ++p;
        ctoken = PPT_COMMA;
        break;
    case '\'':
    case '\"':
        p = PPScanLiteral( p );
        ctoken = PPT_LITERAL;
        break;
    case '.':
        if( p[1] >= '0' && p[1] <= '9' ) {
            p = PPScanNumber( p );
            ctoken = PPT_NUMBER;
        } else {
            p = PPScanOther( p );
            ctoken = PPT_OTHER;
        }
        break;
    case ' ':
    case '\t':
    case '\r':
    case '\n':
        p = PP_SkipSpace( p, &white_space );
        ctoken = PPT_WHITE_SPACE;
        break;
    case ';':
    case '/':
        p2 = PP_SkipComment( p, &white_space );
        if( white_space ) {
            p = p2;
            ctoken = PPT_COMMENT;
        } else {
            p = PPScanOther( p );
            ctoken = PPT_OTHER;
        }
        break;
    case '#':
        if( PPFlags & PPFLAG_ASM_COMMENT ) {
            p2 = PP_SkipComment( p, &white_space );
            if( white_space ) {
                p = p2;
                ctoken = PPT_COMMENT;
            } else {
                p = PPScanOther( p );
                ctoken = PPT_OTHER;
            }
            break;
        }
        // Fall through!
    default:
        if( p[0] == PreProcChar ) {
            if( p[1] == PreProcChar ) {
                p += 2;
                ctoken = PPT_SHARP_SHARP;
            } else {
                ++p;
                ctoken = PPT_SHARP;
            }
        } else if( p[0] >= '0' && p[0] <= '9' ) {
            if( p[1] == 'x' || p[1] == 'X' ) {
                p = PPScanHexNumber( p );
            } else {
                p = PPScanNumber( p );
            }
            ctoken = PPT_NUMBER;
        } else if( p[0] == 'L' && (p[1] == '\'' || p[1] == '\"') ) {
            p = PPScanLiteral( p + 1 );
            ctoken = PPT_LITERAL;
        } else if( isalpha( p[0] ) || p[0] == '_' ) {
            p = PP_ScanName( p );
            ctoken = PPT_ID;
        } else {
            p = PPScanOther( p );
            ctoken = PPT_OTHER;
        }
        break;
    }
    *token = ctoken;
    return( p );
}
Beispiel #2
0
char *PP_ScanToken( char *p, char *token )
{
    char        *p2;
    char        c;
    char        white_space;

    if( PPFlags & PPFLAG_SKIP_COMMENT ) {
        *token = PPT_COMMENT;
        for( ;; ) {
            if( *p == '\0' ) break;
            if( *p == '*'  &&  p[1] == '/' ) {
                p += 2;
                PPFlags &= ~PPFLAG_SKIP_COMMENT;
                break;
            }
            ++p;
        }
        return( p );
    }
    c = *p;
    switch( *p ) {
    case '(':
    case ')':
    case ',':
        p2 = p + 1;
        break;
    case '\'':
    case '\"':
        p2 = PPScanLiteral( p );
        c = PPT_LITERAL;
        break;
    case '.':
        if( p[1] >= '0'  &&  p[1] <= '9' ) {
            p2 = PPScanNumber( p );
            c = PPT_NUMBER;
        } else {
            p2 = PPScanOther( p );
            c = PPT_OTHER;
        }
        break;
    case ' ':
    case '\t':
    case '\r':
    case '\n':
        p2 = PP_SkipSpace( p, &white_space );
        c = PPT_WHITE_SPACE;
        break;
    case ';':
    case '/':
        p2 = PP_SkipComment( p, &white_space );
        if( white_space ) {
            c = PPT_COMMENT;
        } else {
            p2 = PPScanOther( p );
            c = PPT_OTHER;
        }
        break;
    case '#':
        if( PPFlags & PPFLAG_ASM_COMMENT ) {
            p2 = PP_SkipComment( p, &white_space );
            if( white_space ) {
                c = PPT_COMMENT;
            } else {
                p2 = PPScanOther( p );
                c = PPT_OTHER;
            }
            break;
        }
        // Fall through!
    default:
        if( c == PreProcChar ) {
            if( p[1] == PreProcChar ) {
                p2 = p + 2;
                c = PPT_SHARP_SHARP;
            } else {
                p2 = p + 1;
                c = PPT_SHARP;
            }
        } else if( c >= '0'  &&  c <= '9' ) {
            if( p[1] == 'x'  ||  p[1] == 'X' ) {
                p2 = PPScanHexNumber( p );
            } else {
                p2 = PPScanNumber( p );
            }
            c = PPT_NUMBER;
        } else if( c == 'L' && (p[1] == '\'' || p[1] == '\"') ) {
            p2 = PPScanLiteral( p + 1 );
            c = PPT_LITERAL;
        } else if( isalpha( c ) || c == '_' ) {
            p2 = PP_ScanName( p );
            c = PPT_ID;
        } else {
            p2 = PPScanOther( p );
            c = PPT_OTHER;
        }
        break;
    }
    *token = c;
    return( p2 );
}