Count of Words Starting with a - Lex Program - Compiler Design

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

0 comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...