Collected from Stack Overflow question
https://stackoverflow.com/questions/50550637/bison-semantic-predicate-syntax-error-stray

Version: 3.04 (also fails on 3.01 and 3.02)
Platform: Linux but I think it would be the same on any platform

To reproduce, it is possible to use the semantic predicate test snippet
already in the bison test suite:

%glr-parser
%expect-rr 1
%%
// Exercise "%?{...}" and "%? {...}".
widget:
 %? {new_syntax} "widget" id new_args  { $$ = f($3, $4); }
| %?{!new_syntax} "widget" id old_args  { $$ = f($3, $4); }
;
id:;
new_args:;
old_args:;
%%

produces (at line 789):

       case 2:
   if (! (#line 6 "sempred.y" /* glr.c:816  */
   new_syntax)) YYERROR;
#line 793 "sempred.tab.c" /* glr.c:816  */
   break;

which of course produces a compiler error.

As a quick workaround, I fixed the problem by altering line 462 of
data/c.m4 to read

if (! (
           $2)) YYERROR;

Reply via email to