Compilation of `oct-parse.*` on macos runners fails with syntax errors (bison 3.8?)

The GitHub runners for macos are failing to build Octave since recently.
Logs: maint: Convert structs _idxadds_helpe, _idxadda_helper to classes. · gnu-octave/octave@e2335f5 (github.com)
Relevant(?) part:

In file included from ../libinterp/parse-tree/oct-parse.yy:84:
libinterp/parse-tree/oct-parse.h:315:51: error: expected ')'
int octave_lex (OCTAVE_STYPE *yylvalp, void *lexer.scanner);
                                                  ^
libinterp/parse-tree/oct-parse.h:315:16: note: to match this '('
int octave_lex (OCTAVE_STYPE *yylvalp, void *lexer.scanner);
               ^
../libinterp/parse-tree/oct-parse.yy:91:13: error: static declaration of 'octave_error' follows non-static declaration
static void yyerror (octave::base_parser& parser, const char *s);
            ^
libinterp/parse-tree/oct-parse.cc:77:25: note: expanded from macro 'yyerror'
#define yyerror         octave_error
                        ^
libinterp/parse-tree/oct-parse.h:312:6: note: previous declaration is here
void octave_error (octave::base_parser& parser, const char *msg);
     ^
../libinterp/parse-tree/oct-parse.yy:2398:1: error: static declaration of 'octave_error' follows non-static declaration
yyerror (octave::base_parser& parser, const char *s)
^
libinterp/parse-tree/oct-parse.cc:77:25: note: expanded from macro 'yyerror'
#define yyerror         octave_error
                        ^
libinterp/parse-tree/oct-parse.h:312:6: note: previous declaration is here
void octave_error (octave::base_parser& parser, const char *msg);
     ^
3 errors generated.
make[2]: *** [libinterp/parse-tree/libparse_tree_la-oct-parse.lo] Error 1
make[2]: *** Waiting for unfinished jobs....

Mentioning @jwe because I think he is the best candidate to understand the parser/lexer.

The first run that failed was the one for octave: e1d9d8ef2b29 (mappers.cc: Skip tests on run-time and don’t mark as regressions).
I don’t know how that could be related. Maybe an update on the runners?

Edit: Might be related: bison was updated from 3.7.6 to 3.8 in homebrew recently:
bison 3.8 · Homebrew/homebrew-core@19d303e (github.com)

Edit 2: See also these notes for their release:
Bison - News: Bison 3.8.1 [Savannah] (gnu.org)

  • Noteworthy changes in release 3.8 (2021-09-07) [stable]

** Backward incompatible changes

In conformance with the recommendations of the Graphviz team
('Re: [graphviz-devel] File extension .dot or .gv?' - MARC), -g/--graph
now generates a *.gv file by default, instead of *.dot. A transition
started in Bison 3.4.

To comply with the latest POSIX standard, in Yacc compatibility mode
(options -y/--yacc) Bison now generates prototypes for yyerror and
yylex. In some situations, this is breaking compatibility: if the user
has already declared these functions but with some differences (e.g., to
declare them as static, or to use specific attributes), the generated
parser will fail to compile. To disable these prototypes, #define yyerror
(to yyerror), and likewise for yylex.

and

  • Noteworthy changes in release 3.8.1 (2021-09-11) [stable]

The generation of prototypes for yylex and yyerror in Yacc mode is
breaking existing grammar files. To avoid breaking too many grammars, the
prototypes are now generated when -y/--yacc is used and the
POSIXLY_CORRECT environment variable is defined.

Avoid using -y/--yacc simply to comply with Yacc’s file name
conventions, rather, use -o y.tab.c. Autoconf’s AC_PROG_YACC macro uses
-y. Avoid it if possible, for instance by using gnulib’s gl_PROG_BISON.

I’m attaching a possible fix.

bison-rule-diffs.txt (2.0 KB)

Homebrew has updated to bison 3.8.1 in the meantime. That seems to have fixed this regression.

I don’t understand the implications of your proposed change. If it is save, it is probably ok to apply it.
But given the fact that bison 3.8.1 was released shortly after bison 3.8, it feels like an “emergency” release. So, it is probably not very likely to come across bison 3.8(.0) in the wild…

I pushed the following change to simplify the rules for running bison by avoiding the need to deal with the old y.tab.h and y.tab.c files that yacc produces.

http://hg.savannah.gnu.org/hgweb/octave/rev/72adc88bc674