[英]Why the below flex code doesn't show output?
digit [0-9]
letter [A-Za-z]
%{
int count;
%}
%%
/* match identifier */
{letter}({letter}|{digit})* count++;
%%
int main(void) {
yylex();
printf("number of identifiers = %d\n", count);
return 0;
}
Doesn't work printf statement . printf语句不起作用。 can you explain what should i include in this code. 您能解释一下我应该在此代码中包括什么吗?
If you have an error with yywrap
-- just add %option noyywrap
: 如果yywrap
出现错误-只需添加%option noyywrap
:
digit [0-9]
letter [A-Za-z]
%{
int count;
%}
%option noyywrap
%%
/* match identifier */
{letter}({letter}|{digit})* count++;
%%
int main(void) {
yylex();
printf("number of identifiers = %d\n", count);
return 0;
}
Then compile: 然后编译:
flex f.l
gcc lex.yy.c
Run and don't forget to send EOF at the end (with Ctrl-D) : 运行, 不要忘记最后发送EOF(使用Ctrl-D) :
./a.out
a a a
number of identifiers = 3
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.