I’m looking at a parser made with flex and bison. Bison 2.5.
I add %locations to the .y file, and recompile, and try to run, I am rewarded with a sigsegv (well, the macosx equivalent):
Program received signal EXC_BAD_ACCESS, Could not access memory.
Reason: KERN_PROTECTION_FAILURE at address: 0x000000010003f123
0x000000010003f38c in yylex (yylval_param=0x7fff5fbff5e8, yyscanner=0x7fff5fbff5d0) at lex.yy.c:2036
2036 *yy_cp = yyg->yy_hold_char;
All this is the generated code, so I don’t really know where to go first to understand how yy_cp ends up pointing to read-only storage.
Note that the lexer source includes
%option noinput
%option reentrant bison-bridge
and the parser source includes
%lex-param {yyscan_t *scanner } /* Call flex functions with this argument */
It looks like you’re using extra args with yylex, possibly via
%option bison-bridgein the lexer and%lex-paramand/or%define api.purein the bison file. So if you add%locationsto the bison file, you need to make the corresponding change to the flex file. It may as simple as just adding%option bison-locations, or it may require changing various macros, depending on what you are doing.