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

7. Lex specification program that generates a C program which takes a string “abcd” and prints the pattern

10. Program in YACC to recognize the string „abbb^n, „ab^n „a^n of the langauge (a^n b^n , n>=1)