Program:
// Lex file: aa.l
%{
int count=0;
%}
alpha [a-zA-Z]
digit [0-9]
space [ \t\n]
start ^a
%%
{start} {count++;}
{space}(a|A)({alpha}|{digit})* {count++;}
. ;
%%
main()
{
yylex();
printf("count= %d\n",count);
}
Output:
nn@linuxmint ~ $ lex aa.l
nn@linuxmint ~ $ gcc lex.yy.c -ll
nn@linuxmint ~ $ ./a.out<tst.txt
count= 6
nn@linuxmint ~ $
// tst.txt
afsal ARIFA aaa www.2k8618.blogspot.com
aiswarya saranya sooraj
arun reshmi
a www.2k8cse.cu.cc
// Lex file: aa.l
%{
int count=0;
%}
alpha [a-zA-Z]
digit [0-9]
space [ \t\n]
start ^a
%%
{start} {count++;}
{space}(a|A)({alpha}|{digit})* {count++;}
. ;
%%
main()
{
yylex();
printf("count= %d\n",count);
}
Output:
nn@linuxmint ~ $ lex aa.l
nn@linuxmint ~ $ gcc lex.yy.c -ll
nn@linuxmint ~ $ ./a.out<tst.txt
count= 6
nn@linuxmint ~ $
// tst.txt
afsal ARIFA aaa www.2k8618.blogspot.com
aiswarya saranya sooraj
arun reshmi
a www.2k8cse.cu.cc
0 comments:
Post a Comment