-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcapitalise.l
44 lines (42 loc) · 834 Bytes
/
capitalise.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
44
/* This program capitalises the comments. Input file is "comments.txt" and output file is "capcom.txt". */
%{
#include<stdio.h>
%}
%%
"/*"([a-zA-Z0-9 ]*[\n]*)*"*/" {
int l=yyleng;
int i=0;
fprintf(yyout,"%c",yytext[0]);
for(i=1;i<l;i++)
{
if(yytext[i-1]==32 || yytext[i-1]==9 || yytext[i-1]==10)
{
fprintf(yyout,"%c",toupper(yytext[i]));
}
else
fprintf(yyout,"%c",yytext[i]);
}
}
"//".* {
int l=yyleng;
int i=0;
fprintf(yyout,"%c",yytext[0]);
for(i=1;i<l;i++)
{
if(yytext[i-1]==32 || yytext[i-1]==9 || yytext[i-1]==10)
{
fprintf(yyout,"%c",toupper(yytext[i]));
}
else
fprintf(yyout,"%c",yytext[i]);
}
}
. {fprintf(yyout,"%s",yytext);}
%%
int main()
{
yyin=fopen("comments.txt","r");
yyout=fopen("capcom.txt","w+");
yylex();
return 0;
}