tags:

views:

1875

answers:

1

I have a simple "language" that I'm using Flex(Lexical Analyzer), it's like this:

/* Just like UNIX wc */
%{
int chars = 0;
int words = 0;
int lines = 0;
%}

%%
[a-zA-Z]+ { words++; chars += strlen(yytext); }
\n        { chars++; lines++; }
.         { chars++; }
%%

int main()
{
    yylex();
    printf("%8d%8d%8d\n", lines, words, chars);
}

The I run a flex count.l, all goes ok without errors or warnings, then when I try to do a cc lex.yy.c I got this errors:

ubuntu@eeepc:~/Desktop$ cc lex.yy.c
/tmp/ccwwkhvq.o: In function yylex': lex.yy.c:(.text+0x402): undefined reference to yywrap'
/tmp/ccwwkhvq.o: In function input': lex.yy.c:(.text+0xe25): undefined reference to yywrap'
collect2: ld returned 1 exit status

What is wrong?

+8  A: 

The scanner calls this function on end of file, so you can point it to another file and continue scanning its contents. If you don't need this, use

%option noyywrap

or link with -lfl to use the default yywrap() function in the library fl.

hjhill
Thanks very much!
Nathan Campos