[net.unix-wizards] Comment recognition in Lex, agai

johnl@haddock.UUCP (05/08/84)

#R:watmath:-766600:haddock:16800012:000:685
haddock!johnl    May  7 14:28:00 1984

The problem with recognizing comments as single Lex tokens is that Lex
has a finite sized token buffer.  If your comments are bigger than the
buffer, you lose.

What should work is to put in a COMMENT start state and do this:

"/*"            BEGIN COMMENT;  /* start a comment */

<COMMENT>"*/"   BEGIN 0;        /* return to regular state */

<COMMENT>.|\n   ;               /* throw everything else away */

Unfortunately, I've never had much luck with making lex programs that
include start states work.  Everybody lets lex recognize the /* and
writes C code to eat the comment; if you read the manual page for lex,
you'll find exactly that in the example.

John Levine, ima!johnl

smk@axiom.UUCP (Steven M. Kramer) (05/11/84)

I had used lex a few years ago and needed (actually wanted) to implement
comments.  I made a special comment state to do it in.   Otherwise, if
you try to match a comment in 1 rule, large comments will blow away the
buffer.  I had no trouble in making a separate state for comments.
Where's the beef?

-- 
	--steve kramer
	{allegra,genrad,ihnp4,utzoo,philabs,uw-beaver}!linus!axiom!smk	(UUCP)
	linus!axiom!smk@mitre-bedford					(MIL)

dan@haddock.UUCP (05/23/84)

#R:sdcrdcf:-109200:haddock:16800013:000:222
haddock!dan    May 22 15:32:00 1984

Or rather, don't bother preparing for comments like those.
The line containing the word "variants" is incorrect, as you
can see by running the message through the C preprocessor.
(It produces an extraneous close-comment.)