lex program to find the largest words and its length
lex code to find the largest words and its length
***************************
%{
int wordlen = 0,i=0; char lwords[100][100];
%}
%option noyywrap
%%
[a-zA-Z]+ {
if (yyleng > wordlen)
wordlen = yyleng;
strcpy(lwords[i++],yytext);
}
%%
int main() {
int j;
yylex();
printf("Maximum length is %d ", wordlen);
printf("largest length words\n");
for ( j=0;j<i;j++)
if(strlen(lwords[j])==wordlen)
printf("%s\n",lwords[j]);
return 0;
}
Execution
flex lword.lex
$ gcc lex.yy.c
$ ./a.out
this is a program to find largest words from the input
Maximum length is 7 largest length words
program
largest
Comments
Post a Comment