Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!rutgers!gatech!gt-cmmsr!auc!maw From: maw@auc.UUCP (Michael A. Walker) Newsgroups: comp.lang.c Subject: Re: Want a way to strip comments from a Summary: Another solution to the comment craze. Message-ID: <32248@auc.UUCP> Date: 30 Mar 89 15:08:19 GMT References: <7150@siemens.UUCP> <9900010@bradley> <4896@cbnews.ATT.COM> <9887@megaron.arizona.edu> Distribution: na Organization: Atlanta University, Atlanta, GA Lines: 58 In article <9887@megaron.arizona.edu>, rupley@arizona.edu (John Rupley) writes: > > > In article <620@gonzo.UUCP>, daveb@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--------------------------