home | codereading | contact | github | math | misc | notes | patches | tech | README

Lex & Yacc (and Flex & Bison) notes


Error ...In function `yyparse': ...: undefined reference to `yylex'

Once, I got an error like:

parser.o: In function `yyparse':
parser.c:(.text+0x3ac): undefined reference to `yylex'

And that was because the lex file (parser.l) and the yacc file (parser.y) had the same radix name (parser.). The build system (automake) was creating a file parser.c from both, so the file generated by lex file was overwriting the one generated by yacc (or the opposite). I had to use different names for the lexical analyzer (that I called tokenizer.l) and the parser (that I called parser.y).

Error ...In function `yylex': ...:968: undefined reference to `yywrap'

I just declared my own yywrap() function (see this link for more details):

tasks.c:int yywrap(void) { return 1; }

Bison seems to have an extension so you can do this:

%option noyywrap