Alien-LibJIT

 view release on metacpan or  search on metacpan

libjit/dpas/dpas-scanner.l  view on Meta::CPAN

# define YY_NO_UNISTD_H
#endif

extern YYSTYPE yylval;

/*
 * Current file and line number.
 */
char *dpas_filename = "";
long dpas_linenum = 1;

/*
 * Return a token code from the lexical analyser.
 */
#define	RETURNTOK(x)		return (x)

/*
 * Parse a string value.
 */
static char *dpas_parse_string(const char *text)
{
	int quote = *text++;
	char *str = (char *)jit_malloc(jit_strlen(text));
	char *temp;
	if(!str)
	{
		dpas_out_of_memory();
	}
	temp = str;
	while(*text != '\0')
	{
		if(text[0] == quote && text[1] == quote)
		{
			*temp++ = (char)quote;
			text += 2;
		}
		else if(text[0] == quote)
		{
			break;
		}
		else
		{
			*temp++ = *text++;
		}
	}
	*temp = '\0';
	return str;
}

/*
 * Parse a floating-point value.
 */
static jit_nfloat dpas_parse_float(const char *text)
{
	double value = 0.0;
	sscanf(text, "%lf", &value);
	return (jit_nfloat)value;
}

/*
 * Infer the best type for an integer constant.
 */
static void dpas_infer_type(YYSTYPE *lval)
{
	jit_ulong value = lval->int_const.value;
	if(value <= (jit_ulong)(jit_long)jit_max_int)
	{
		lval->int_const.type = jit_type_int;
	}
	else if(value <= (jit_ulong)jit_max_uint)
	{
		lval->int_const.type = jit_type_uint;
	}
	else if(value <= (jit_ulong)jit_max_long)
	{
		lval->int_const.type = jit_type_long;
	}
	else
	{
		lval->int_const.type = jit_type_ulong;
	}
}

/*
 * Parse a decimal integer value.
 */
static void dpas_parse_decimal(const char *text, YYSTYPE *lval)
{
	jit_ulong value = 0;
	while(*text != '\0')
	{
		value = value * 10 + (jit_ulong)(*text - '0');
		++text;
	}
	lval->int_const.value = value;
	dpas_infer_type(lval);
}

/*
 * Parse a hexadecimal integer value.
 */
static void dpas_parse_hex(const char *text, YYSTYPE *lval)
{
	jit_ulong value = 0;
	while(*text != '\0')
	{
		if(*text >= '0' && *text <= '9')
		{
			value = value * 16 + (jit_ulong)(*text - '0');
		}
		else if(*text >= 'A' && *text <= 'F')
		{
			value = value * 16 + (jit_ulong)(*text - 'A' + 10);
		}
		else if(*text >= 'a' && *text <= 'f')
		{
			value = value * 16 + (jit_ulong)(*text - 'a' + 10);
		}
		++text;
	}
	lval->int_const.value = value;



( run in 0.665 second using v1.01-cache-2.11-cpan-cdf2f3d4e48 )