Here is the answer to a more complex version of this problem that is difficult to solve by simply adding an ad.
GNU Bison supports the generation of paired pairs that work with Flex (using Flex %option bison-bridge re-entrant ). Berkeley Yacc provides a compatible implementation.
Here is a guide to solving this undeclared yylex for both parser generators.
With a repeat member, "Bison bridged" lexer, a yylex ad turns into this:
int yylex(YYSTYPE *yylval, void *scanner);
If you place this prototype in the initial header section %{ ... %} your Yacc parser and generate a parser using Bison or Berkeley Yacc, the compiler will complain that YYSTYPE not declared.
You cannot just create a forward ad for YYSTYPE because in Berkeley Yacc it does not have a union tag. In Bison it is typedef union YYSTYPE { ... } YYSTYPE , but in Berkeley Yacc it is typedef { ... } YYSTYPE : no tag.
But, in Berkeley Yacc, if you place an ad in the third section of the analyzer, it is in the yylex call area! So, the following works for Berkeley yacc:
%{ %} %% %% int yylex(YYSTYPE *, void *);
If this is generated with Bison, the problem persists: there is no prototype in yylex .
This minor fix makes it work for GNU Bison:
%{ #if YYBISON union YYSTYPE; int yylex(union YYSTYPE *, void *); #endif %} %% %% int yylex(YYSTYPE *, void *);
There you go.