implicit declaration of function 'yylex' is invalid in C99

Ryan Schmidt <[email protected]> Fri, 14 Jan 2022 03:52:24 -0600
Newsgroups gmane.comp.parsers.bison.bugs
Message-ID <[email protected]>
Hi,

On macOS 10.15 or later with bison 3.8.2, flex 2.6.4, and Xcode 12 or later, when software is built that uses bison/flex, I often see this type of failure:


error: implicit declaration of function 'yylex' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
      yychar = YYLEX;
               ^
note: expanded from macro 'YYLEX'
# define YYLEX yylex ()
               ^


As of Xcode 12, implicit declaration of function is an error. You must provide a function prototype before you call a function.

A quick search shows many people encountering this problem:

https://stackoverflow.com/questions/69986502/i-get-some-error-when-i-try-to-complie-yacc-lex-file
https://stackoverflow.com/questions/23717039/generating-a-compiler-from-lex-and-yacc-grammar
https://trac.macports.org/ticket/62015
https://trac.macports.org/ticket/62632

It sounds very much like the problem reported to this mailing list in 2005:

https://lists.gnu.org/archive/html/bug-bison/2005-05/msg00055.html

A fix was proposed there as well. Does anyone know if that proposal was ever accepted? It's difficult for me to determine because I'm not familiar with the bison source code and it has probably evolved significantly since 2005.

I don't know much about bison and flex. If this is actually a flex bug let me know and I can report it over there.