Tuesday, 3 December 2013

Even number of 1's using Flex [ lex program part 7 ]




program

     

%{
int c=0;
%}
str [1]*
%%

{str} c++;

%%

void main()
{
int b;
printf("Enter a binary number \n");
yylex();
printf("value %d",c);
b=c%2;
if(b==0)
printf(" accepted \n");
else
printf(" rejected \n");
}
        
    

Output code

   

lex even.l
cc lex.yy.c -lfl
./a.out
        
    
 then press CTRL+d

0 Comments:

Post a Comment

Facebook Twitter Delicious Digg Stumbleupon Favorites More

 
Design by Free WordPress Themes | Bloggerized by Lasantha - Premium Blogger Themes | coupon codes