Want a way to strip comments from a

John Rupley rupley at arizona.edu
Tue Mar 28 20:04:16 AEST 1989


In article <795 at twwells.uucp>, bill at twwells.uucp (T. William Wells) writes:
> In article <9797 at megaron.arizona.edu> rupley at arizona.edu (John Rupley) writes:
> : A Lex source for uncommenting is attached (which I hope does not belie
> : the remark above about hard to get the logic wrong :-).
> 
> Try it on a very long comment. You might discover an overflowed lex
> buffer. On the other hand, this shouldn't be too hard to fix. Just do
> for the comment what you did for the noncommented text.

Nope.... no problem.... comments are thrown away line-by-line, by design,
so that very long comments indeed do not blow the buffer.

A very long string, however, will overflow the buffer, but clearly this
is understood, and it can be viewed as a feature, although
idiosyncratic, as noted in <9888 at megaron.arizona.edu>.  If you want to
handle strings differently, add another start condition (state) begun
by '"' and make explicit start condition 0 = <INITIAL>, or change the
size of the match buffer (yytext[]) by including in the definitions:

	%{
	#define YYLMAX 5000	/* or whatever */
	%}

John Rupley
rupley!local at megaron.arizona.edu



More information about the Comp.lang.c mailing list