3,881
社区成员
发帖
与我相关
我的任务
分享
%{
#include <stdio.h>
#include <string.h>
FILE *hyplink;
int lastchar; /* if last output char is newline */
%}
%x NONEED
%x FORM
%x LINK
%x SCPT
%x TAG
%x COMMENT
%%
("<"[sS][cC][rR][iI][pP][tT][^>]*">") BEGIN(SCPT);
("<"[sS][tT][yY][lL][eE][^>]*">") BEGIN(NONEED);
"<"[iI][fF][rR][aA][mM][eE][^>]*">" BEGIN(NONEED);
("<!--"[sS][cC][rR][iI][pP][tT][^>]*">") BEGIN(SCPT);
("<"[Ff][oO][rR][Mm][^>]*">") BEGIN(FORM);
"<"[aA] BEGIN(LINK);
"<" BEGIN(TAG);
<NONEED>"</"[sS][tT][yY][lL][eE][^>]*">" BEGIN(INITIAL);
<NONEED>"</"[iI][fF][rR][aA][mM][eE][^>]*">" BEGIN(INITIAL);
<NONEED>.|\n ;
<SCPT>"/"[sS][cC][rR][iI][pP][tT][^>]*">"+(\n)* BEGIN(INITIAL);
<SCPT>.|\n {; }
<FORM>("</"[Ff][oO][rR][Mm][^>]*">"+(\n)*) BEGIN(INITIAL);
<FORM>.|\n { ;
/* like NONEED, SCPT and FORM, 请完成TAG, LINK条件模式下对应
正则表达式和对应的C语言动作 */
}
(&[qQ][oO][tT]";") {
printf("'");
}
(&[gG][tT]";") {
printf(">");
}
(&[lL][tT]";") {
printf("<");
}
(&[aA][mM][pP]";") {
printf("&");
}
(&[nN][bB][sS][pP]";") {
printf(" ");
}
[\r\t]* {; }
("</"[lL][iI]">") {; }
("</"[pP]">") {; }
("-->") {; }
%%
int main(int argc, char **argv )
{
++argv, --argc;
if ( argc > 0 ) {
if ((yyin = fopen( argv[0], "rb" )) == NULL) {
printf("the file %s could'nt open!\n", argv[0]);
exit (1);
}
}
else
yyin = stdin;
if ((hyplink = fopen("hyplink.txt", "w")) == NULL) {
printf("coud'nt create hyperlink file!\n");
exit(1);
}
yylex();
fclose(yyin);
fclose(hyplink);
return 0;
}
int yywrap()
{
return 1;
}