Alien-LibJIT

 view release on metacpan or  search on metacpan

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

			RETURNTOK(IDENTIFIER);
		}

{DIGIT}+{EXPONENT}	{ yylval.real_const = dpas_parse_float(yytext);
		  	  RETURNTOK(REAL_CONSTANT); }
{DIGIT}+"."{DIGIT}*{EXPONENT}	{ yylval.real_const = dpas_parse_float(yytext);
		  		  RETURNTOK(REAL_CONSTANT); }
{DIGIT}+"."{DIGIT}+	{ yylval.real_const = dpas_parse_float(yytext);
		  	  RETURNTOK(REAL_CONSTANT); }
{DIGIT}+"."[^.]		{ yylval.real_const = dpas_parse_float(yytext);
			  RETURNTOK(REAL_CONSTANT); }

{DIGIT}{HEX}*[hH]	{ dpas_parse_hex(yytext, &yylval);
			  RETURNTOK(INTEGER_CONSTANT); }

{DIGIT}+		{ dpas_parse_decimal(yytext, &yylval);
			  RETURNTOK(INTEGER_CONSTANT); }

{WHITE}+		;

\n			{ ++dpas_linenum; }

"{"			{ dpas_skip_comment(0); }
"(*"			{ dpas_skip_comment(1); }

.			{ RETURNTOK(((int)(yytext[0])) & 0xFF); }

%%

void dpas_load_file(char *filename, FILE *file)
{
	char *saved_filename;
	long saved_linenum;
	YY_BUFFER_STATE saved_buffer;
	YY_BUFFER_STATE new_buffer;
	extern int yyparse(void);

	/* Save the current state */
	saved_filename = dpas_filename;
	saved_linenum = dpas_linenum;
	saved_buffer = YY_CURRENT_BUFFER;

	/* Create a buffer for the new file */
	new_buffer = yy_create_buffer(file, BUFSIZ);
	if(!new_buffer)
	{
		dpas_out_of_memory();
	}

	/* Switch to the new state */
	dpas_filename = filename;
	dpas_linenum = 1;
	yy_switch_to_buffer(new_buffer);

	/* Call the parser */
	if(yyparse())
	{
		dpas_error_reported = 1;
	}

	/* Bail out if this was the top-most file in the parse process,
	   because flex cannot switch to a NULL buffer */
	if(!saved_buffer)
	{
		return;
	}

	/* Switch back to the original file */
	dpas_filename = saved_filename;
	dpas_linenum = saved_linenum;
	yy_switch_to_buffer(saved_buffer);

	/* Delete the buffer that we used on the file we just parsed */
	yy_delete_buffer(new_buffer);
}

/*
 * Skip a comment in the input stream.
 */
static void dpas_skip_comment(int star_style)
{
	int ch;
	for(;;)
	{
		ch = input();
		if(ch == EOF)
		{
			break;
		}
		else if(ch == '}' && !star_style)
		{
			break;
		}
		else if(ch == '*' && star_style)
		{
			ch = input();
			while(ch == '*')
			{
				ch = input();
			}
			if(ch == EOF || ch == ')')
			{
				break;
			}
			else if(ch == '\n')
			{
				++dpas_linenum;
			}
		}
		else if(ch == '\n')
		{
			++dpas_linenum;
		}
	}
}



( run in 0.494 second using v1.01-cache-2.11-cpan-5b529ec07f3 )