/* def*/
%{
#include <stdio.h>
int vowelCount = 0;
int consonantCount = 0;
%}
/*RULES*/
%%
[aeiouAEIOU] {vowelCount = vowelCount + 1;}
[A-Za-z][^aeiouAEIOU] {consonantCount = consonantCount + 1;}
%%
/*fct*/
int main(void)
{
yylex();
printf ("il y a %d voyelles",vowelCount);
printf ("il y a %d consonnes",consonantCount);
return 0;
}
This is my first ever lex program. I want it to count how many vowels and how many consonants are in the source..
I'm having 2 problems:
I don't get the
printfafter yylex until after doing Ctrl+C, and stopping execution. so yylex isn't letting any instructions after it, execute unless I quit stop the entire executionI'm not geting the correct numbers. For example for "good", I got 1 vowel and 1 consonant instead of 2 vowels and 2 consonants.
What do I need to do to fix these problems?