我在这个 lex 程序中遇到无法识别的规则错误
I am getting error as unrecognized rule in this lex program
%{
#include<stdio.h>
int vowel=0;
%}
%%
[aeiouAEIOU]
{
vowel++;
}
%%
int main()
{
char str[200];
gets(str);
yylex();
printf("Vowels:",vowel);
}
如果那是您编写程序的方式,那么错误是正确的。在 Flex 中,规则的操作必须与模式在同一行开始。
来自flex manual:
5.2 Format of the Rules Section
The rules section of the flex input contains a series of rules of the form:
pattern action
where the pattern must be unindented and the action must begin on the same line.
如所写,您已提供 {
作为模式。那不是一个有效的模式,因此 flex 抱怨。
%{
#include<stdio.h>
int vowel=0;
%}
%%
[aeiouAEIOU]
{
vowel++;
}
%%
int main()
{
char str[200];
gets(str);
yylex();
printf("Vowels:",vowel);
}
如果那是您编写程序的方式,那么错误是正确的。在 Flex 中,规则的操作必须与模式在同一行开始。
来自flex manual:
5.2 Format of the Rules Section
The rules section of the flex input contains a series of rules of the form:
pattern action
where the pattern must be unindented and the action must begin on the same line.
如所写,您已提供 {
作为模式。那不是一个有效的模式,因此 flex 抱怨。