为什么下面的flex代码不显示输出?

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了为什么下面的flex代码不显示输出?相关的知识,希望对你有一定的参考价值。

digit  [0-9]
letter [A-Za-z]
%{
int count;
%}
%%
     /* match identifier */
{letter}({letter}|{digit})*  count++;
%%
int main(void) {
yylex();
printf("number of identifiers = %d
", count);
return 0;
}

printf语句不起作用。你能解释我应该在这段代码中包含什么。

答案

如果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
", count);
    return 0;
}

然后编译:

flex f.l
gcc lex.yy.c

运行并且不要忘记最后发送EOF(使用Ctrl-D):

./a.out
a a a

number of identifiers = 3

以上是关于为什么下面的flex代码不显示输出?的主要内容,如果未能解决你的问题,请参考以下文章

片段中的ListView不显示

ActionScript 库项目与 Flex 库项目

Javascript代码片段在drupal中不起作用

(转) Java中的负数及基本类型的转型详解

输入为啥不尊重flex?

为啥显示:-ms-flex; -ms-justify-content:中心;不能在 IE10 中工作? [关闭]