flex reject bug

Greg Lee lee at uhccux.UUCP
Sat May 7 04:14:26 AEST 1988



When a flex-created program is asked to reject a string
matched by a pattern ending in $, it appears that one too
few characters is pushed back, in some circumstances.
The following demonstrates the problem -- the program "test"
loops endlessly pushing back and accepting the last character
of a line.
	Greg, lee at uhccux.uhcc.hawaii.edu

---------contents of file test.l-------
%%

.*$	{	printf("%s REJECT\n", yytext);
		REJECT;
	}

.*$	{	printf("%s ACCEPT\n", yytext);
	}

. |
\n	;

%%

main()
{	yylex();
}
----------------eof--------------------

---------contents of file xtext--------
Text ending with X
----------------eof--------------------
(There is a newline after the "X".)

Test program made with flex -r gives following results.

Output of "test <xtext":
---------begin test output-------------
Text ending with X REJECT
Text ending with  ACCEPT
X REJECT
 ACCEPT
X REJECT
 ACCEPT
X REJECT
 ACCEPT
and so on, ad infinitum.
---------------------------------------

Test program made with lex gives following results.

Output of "test <xtext":
---------begin test output-------------
Text ending with X REJECT
Text ending with X ACCEPT

 REJECT

 ACCEPT
----------end test output--------------



More information about the Comp.sources.bugs mailing list