Want a way to strip comments from a

Michael A. Walker maw at auc.UUCP
Fri Mar 31 01:08:19 AEST 1989


In article <9887 at megaron.arizona.edu>, rupley at arizona.edu (John Rupley) writes:
> 
> > In article <620 at gonzo.UUCP>, daveb at gonzo.UUCP (Dave Brower) writes:
> > So, I offer this week's challenge:  Smallest program that will take
> > "blank line" style cpp output on stdin and send to stdout a scrunched
> > version with appropriate #line directives.  [f]lex, Yacc, [na]awk, sed,
> > perl, c, c++ are all acceptable.  This will be an amusing excercise in
> > typical text massaging that can be enlightening for many people.
> 
> "Scrunching" is probably a matter of taste, with regard to the format
> of the ouput.

I don't know what is ment by the term scrunching, but here is my entry to
the problem of removing comments in a C program.  YACCR (Yet Another C
Comment Remover :-) is a crazy looking lex specification that removes C
comments from a source file.  It also does not put out a lot of extra blank
lines that cpp does.  I have tested on most styles of C comments that I
have seen and it seems to work,  but PLEASE no flames if it doesn't!!!!

In an earlier message, someone address the problem of a yytext overflow.
YACCR redefines the YYLMAX constant as 500, but you can test it with other
values.

To use:
	1.  Save message in file called yaccr.l and edit this file to
	    unwanted text.

	2.  Type: lex yaccr.l

	3.  Type: cc lex.yy.c -ll -lyaccr

It should then be ready to go.

Good luck.

---mike
EMAIL: ...!gatech!auc!rambro!maw

--------------------------------cut here--------------------------
%{
/*
**	Specification:	YACCR
**	Description  :	YACCR removes comments from C programs.
*/

#define CR		0x0d

#ifdef YYLMAX
#undef YYLMAX
#define YYLMAX		500
#endif
%}

%%

"/*""*"*("/*"*|[^*/]|[^*]"/"|"*"[^/])*"*"*"*/"	putchar(CR);
.						printf("%s",yytext);
--------------------------------cut here--------------------------



More information about the Comp.lang.c mailing list