没有得到 LEX 程序的输出

问题描述

我正在尝试运行一个 lex 程序来查找给定字符串中元音和辅音的数量。程序接受输入但不给出输出。给出 input 后​​,程序接受输入但不给出输出,也不会终止。 请帮我找出错误。 我也在这里附上代码

%{ 
#include<stdio.h>
int vowel=0;
int consonant=0; 
%} 
%% 
[aeIoUAEIoU] {voweL++ ;} 
[a-zA-Z] {consonant++ ; } 
%% 
int yywrap()
{
return 1;
} 
int main() 
{ 
printf("Enter the string :"); 
yylex();
printf("Number of vowels are:  %d\n",vowel); 
printf("Number of consonants are:  %d\n",consonant); 
return 0; 
}  

解决方法

最后,我在代码中添加了一点点输出。 更新后的代码如下:

%{ 
#include<stdio.h>
int vowel=0;
int consonant=0; 
%} 
%% 
[aeiouAEIOU] {vowel++ ;} 
[a-zA-Z] {consonant++ ; } 
"\n" return 0;
%% 
int yywrap()
{
return 1;
} 
int main() 
{ 
printf("Enter the string :"); 
yylex();
printf("Number of vowels are:  %d\n",vowel); 
printf("Number of consonants are:  %d\n",consonant); 
return 0; 
}