Lex bugs

Stavros Macrakis macrakis at harvard.ARPA
Wed Sep 4 05:19:59 AEST 1985


The trivial Lex sources "%%\n" and "%%\n%%\n" appear never to work
correctly.  I am not being perverse in noting this (although I am a
firm believer in the importance of the trivial cases working
correctly); rather, these were the simplest subcases I found of cases
where I was having problems.

Call the source file a.l.

A)  lex a.l; cc lex.yy.c -ll; a.out	-> no-op (returns immediately)
B)  lex a.l; cc lex.yy.c; 
	ld lex.yy.o -ll -lc; a.out  	-> illegal instr.
C)  lex a.l; cc lex.yy.c;
		    ld lex.yy.o -ll	-> undef symbols (not surprising)

Note that the Lesk and Schmidt paper in the Unix Programmer's Manual
(3/84) states that "[t]he absolute minimum Lex program is thus `%%',
which translates into a program which copies the input to the output
unchanged."  Case A, which is the only case that executes without
error, does not do this, but rather immediately returns, ignoring the
input.

Case B is a different bug.  Case C is there to show that the `-lc' is
necessary.  Apparently, main/_main is not getting defined properly.
dbx also has severe problems in dealing with lex-generated programs.
The problems seem to go away if you link in a program which
explicitly defines main and calls exit.  This does not appear to be
documented anywhere, and even if it were, there should still be some
sort of link error if main is not defined.

Lex version Berkeley 4.1 8/11/83



More information about the Comp.bugs.4bsd.ucb-fixes mailing list