The semantic predicates feature was added in bison 3.0, released at the end of July, 2013; at this writing, it's not yet bundled into most OS distributions so you need to install from source to even try it. However, I took a quick glance at the bison source code (as of October 10, 2013, and found what looks like a bug in the scanner specification, at line 269 of scan.gram.l
The pattern in that line will match %{nonletter}[[::graph:]]+
(where nonletter is anything other than an alnum, %
or {
), which will certainly match %?{
However, it will not match %? {
. I tried the example from the manual, and indeed:
widget:
%?{ new_syntax } "widget" id new_args { $$ = f($3, $4); }
| %?{ !new_syntax } "widget" id old_args { $$ = f($3, $4); }
;
produces the error you see, while
widget:
%? { new_syntax } "widget" id new_args { $$ = f($3, $4); }
| %? { !new_syntax } "widget" id old_args { $$ = f($3, $4); }
;
does not.
I believe the fix would be to add ?
to the characters not matched by {notletter}
. At least, I tried that, and afterwards both of the above snippets "worked" (at least to the extent that bison generated a .c file.)