18. Sample program to count vowels in
input
%{
#include<stdio.h>
int vowel=0
%}
%%
"a"|"e"|"i"|"o"|"u"|"A"|"E"|"I"|"O"|"U" {printf("is a VOWEL");vowel++;}
%%
int yywrap()
{
return 1;
}
int main()
{
printf("Enter Stringn");
yylex();
printf("vowel=%d โ, vowel);
return 0;
}
18
19. Compilation & Execution of your
Program:
โข Open Command prompt and switch to your working
directory where you have stored your lex file (โ.lโ)
โข Let your lex file be โhello.lโ
โข Now, follow the preceding steps to compile and run
your program.
flex hello.l
gcc lex.yy.c
./a.out
19