Beispiel #1
0
Datei: lex.c Projekt: gyc2015/GYC
static int ScanNumericLiteral()
{
    int base = 10;
    if('.' == *CURSOR)
    {
        return ScanFloatLiteral();
    }

    if('0' == *CURSOR && (CURSOR[1] == 'x'|| CURSOR[1] == 'X'))
    {
        base = 16;
        CURSOR += 2;
        while(IsHexDigit(*CURSOR))
        {
            CURSOR++;
        }
    }
    else if('0' == *CURSOR)
    {
        base = 8;
        CURSOR++;
        while(IsOctDigit(*CURSOR))
        {
            CURSOR++;
        }
    }
    else
    {
        CURSOR++;
        while(IsDigit(*CURSOR))
        {
            CURSOR++;
        }
    }

    if(base == 16 || (*CURSOR == '.' && *CURSOR == 'e' && *CURSOR == 'E'))
    {
        while('u' == *CURSOR || 'U' == *CURSOR ||
              'l' == *CURSOR || 'L' == *CURSOR)
        {
            CURSOR++;
        }
        return TK_INTCONST;
    }
    else
    {
        return ScanFloatLiteral();
    }
}
Beispiel #2
0
/* 扫描常数序列 */
static int ScanNumericLiteral (void) 
{
    unsigned char *start = CURRENT;
    /* 表示数值是多少进制 */
    unsigned char base = 10;

    if ('.' == *CURRENT) {
        return ScanFloatLiteral (start);
    }

    /* 扫描前半部分(小数点的左边) */
    if ('0' == *CURRENT && ('x' == CURRENT[1] || 'X' == CURRENT[1])) {
    
        base = 16;
        start = (CURRENT += 2);
        if (!IsHexDigit (*CURRENT)) {
            
            Error (&TokenCoord, "Expect hex digit");
            TokenValue.i[0] = 0;
            return TK_INTCONST;
        }
        while (IsHexDigit (*CURRENT))
            CURRENT++;
    } else if ('0' == *CURRENT) {
    
        base = 8;
        while (IsOctDigit (*++CURRENT));
    } else {
        while (IsDigit (*++CURRENT));
    }

    /* 如果符合下边条件,按整形处理 */
    if (16 == base || ('.' != *CURRENT && 'e' != *CURRENT && 'E' != *CURRENT)) 
        return ScanIntLiteral (start, (int)(CURRENT - start), base);
    else return ScanFloatLiteral (start);
} 
Beispiel #3
0
/* 处理浮点常量和.../. 操作 */
static int ScanDot(void)
{
	if (IsDigit(CURRENT[1])) {

		return ScanFloatLiteral(CURRENT);
	} else if (CURRENT[1] == '.' && CURRENT[2] == '.') {

		CURRENT += 3;
		return TK_ELLIPSE;
	} else {

		CURRENT++;
		return TK_DOT;
	}
}