-
Notifications
You must be signed in to change notification settings - Fork 0
/
remove.l
44 lines (42 loc) · 796 Bytes
/
remove.l
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
%{
int count=0;
int line_no = 0;
// \/\/.* ;
%}
forward \/
line ['\n']
single {forward}{forward}.*
star \*
not_star [^\*]
not_forward [^\/]
space [ ]
tab ['\t']
hash #.*
multi {forward}{star}({space}|{tab}|{not_star}|{star}{not_forward}|{line})*{star}{forward}
string_literal \".*\"
not_new_line [^'\n']
%%
{single} {count++;
fprintf(yyout,"");
}
{multi} {count++;
fprintf(yyout,"");
}
{hash} {count++;
fprintf(yyout,"");
}
{string_literal} {fprintf(yyout,"%s", yytext);
}
%%
int main(){
fprintf(yyout,"");
printf("\nRemoving comments ...\n");
yyin=fopen("test.php","r");
yyout=fopen("op.php","w");
yylex();
printf("\nNumber of comments : %d\n",count);
printf("\nNumber of lines: %d\n", yylineno);
fclose(yyin);
fclose(yyout);
return(0);
}