Wednesday, September 2, 2020

Write a Lex Program to count number of words.

EXAMPLE :-

%{ #include<stdio.h> #include<string.h> int s = 0; %} %% ([a-zA-Z0-9])* {s++;} "\n" {printf("%d\n", s); s = 0;} %% int yywrap(void){} int main() { yylex(); return 0; }


OUTPUT


sunny@sunny-PC:~/Desktop$ flex nw.l sunny@sunny-PC:~/Desktop$ gcc lex.yy.c sunny@sunny-PC:~/Desktop$ ./a.out Computer Science 2




No comments:

Post a Comment

Please do not any spam link in Comment Box