- 论坛徽章:
- 1
|
用C来解决的办法。只适合配对的注释符的情况。前注释符被续行符分为两行的情况。
文件lex.l如下:
%{
static skipcmnts();
%}
%%
"/*" {skipcmnts();};
[\/][\\][\n]* {skipcmnts();};
%%
extern FILE *fp2;
extern FILE *yyout;
static skipcmnts()
{ char ch;
for(;![](static/image/smiley/default/icon_wink.gif)
{
while((ch=input()) != '*');
if((ch=input()) == '/') return;
if(ch== '*') unput(yytext[yyleng-1]);
}
}
/* End of file */
文件main.c如下:
#include <ctype.h>
#include <stdio.h>
#include <sys/types.h>
#include <string.h>
yywrap() {return(1);}
main (ac,av)
int ac;
char *av[];
{
yyin = stdin;
yyout = stdout;
while(yylex()) {}
}
/* end of file */
文件makefile如下:
m: m.c
cc -o m m.c
lex.yy.c: lex.l
lex lex.l
m.c: main.c lex.yy.c
cat lex.yy.c main.c > m.c
#end of file
编译:
make m
执行:
./m < xxx.c > xxx1.c
[ 本帖最后由 zongyaotang 于 2006-11-1 08:15 编辑 ] |
|