3. Lex program to find the length of the longest word

 

Lex program to find the length of the longest word

 /*Write a Lex program that finds the length of the longest word (defined as a contiguous
 string of upper and lower case letters) in the input.*/
 
%{ #include<stdio.h>
int k=0;
%}

%%
[a-zA-Z]+ {
if(yyleng>k)
{  k= yyleng;
}
}
%%

int main(int argc[],char **argv[])
{
 yyin=fopen("abc.txt","r");
 yylex(); 
 printf("largest: %d",k);
 printf("\n");
 return 0;
}
 
 //file abc.txt
 
Lex program to find the length of the longest word
Lex program to find the length of the longest word

//Output of the above program

Lex program to find the length of the longest word

Lex program to find the length of the longest word

Comments

Popular posts from this blog

Compiler Design

6. Lex program to count the number of words,small and capital letters, digits and special characters in a C file