Lex program that finds the lenght of 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 longest_word=0;
%}

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

int main()
{
 yyin=fopen("abc.txt","r");
 yylex(); 
 printf("largest: %d",longest_word);
 printf("\n");
 return 0;
}

// abc.txt file
output:

No comments:

Post a Comment

Featured post

Amazon Interview Process

On July 5, 1994, Jeff Bezos started the world's most "customer-centric" firm out of his garage in Bellevue, Washington. The A...