/*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