1
對於example.l lex文件,我得到下面的錯誤。如果我註釋掉printf
,它就會消失。我認爲lex規範的頂部部分可以包含%{
和%}
之間的任意C代碼。我需要能夠在lex匹配任何東西之前打印一些輸出。我做了什麼錯,我該如何解決?gcc在編譯lex輸出時給出printf錯誤
$ cat example.l
%{
#include <stdio.h>
printf("foobar\n");
%}
%%
. ECHO;
$ lex example.l
$ gcc -g -L/usr/lib/flex-2.5.4a -lfl -o example lex.yy.c
example.l:3: error: expected declaration specifiers or '...' before string constant
example.l:3: warning: data definition has no type or storage class
example.l:3: error: conflicting types for 'printf'
example.l:3: note: a parameter list with an ellipsis can't match an empty parameter name list declaration
啊,是的,這似乎是完全明顯的,現在你已經說了。謝謝! – 2012-02-06 21:47:05