简体   繁体   English

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

[英]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.

相关问题 为什么这段代码输出什么? - Why doesn't this code output anything? 代码没有打印预期的输出,为什么? - The Code doesn't print the expected output, why? 代码在编译时没有显示错误,但它不显示任何输出 - The code shows no error on compilation,but it doesn't show any output Visual Studio Code 中的 GDB 不显示 printf() output 到标准输出 - GDB in Visual Studio Code doesn't show printf() output to stdout 为什么循环中的 n mod 10 不显示输出 - why n mod 10 in loop doesn't show output 为什么在程序退出之前我的输出不显示? - Why doesn't my output show up until the program exits? 在下面的 C 代码中与指针及其 output 相关,那么为什么值 a[1] 即 20 没有存储在连续地址 de9 中? - In this below C code related to pointers and its output, then why doesn't the value a[1] i.e 20 get stored at consecutive address de9? 为什么这是下面c代码12的output? - Why is this the output of the below c code 12? 为什么相同的生成汇编代码不会导致相同的 output? - Why doesn't the same generated assembler code lead to the same output? 为什么代码显示对管道的写不能确保原子性? - why the code show write to pipe doesn't ensure atomic?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM