In section 1.5.4 Controlling a Parse with Arbitrary Predicates: The bison manual specifies that you can make a parse fail up front for an option in a rule by checking the return of the predicate between the brackets in this format:
parent_rule: %?{ test_predicate_flag } child_rule_1 |
%?{ !test_predicate_flag } child_rule_2;
The problem is that I get this syntax error with the above format in my grammar file:
error: invalid directive: ‘%?{’
I added the %glr-parser
flag before the first %%
as stated in the manual. Is there something I'm missing?
update: attempted this with bison version 3.0 prior to posting and didn't work. Not much information online about people's experience with this "experimental feature" as the doc says. Can anyone confirm or deny that it works for them?
update #2: After following the solution that rici posted, the resulting .c file has issues. It seems that in attempt to aid compile debug, bison outputs #line directives of the following format:
#line <line_no> <grammar_file_prefix>.tab.c
In the case of the arbitrary predicate generation, the above predicate option for the rule ends up in the parser file's main switch block as this:
if (! (#line <line_no> <grammar_file_prefix>.tab.c
This will of course not compile, and I'm guessing is intended to be output on the line before the start of the case statement like I see in the rest of the rule match options. Perhaps another bit of information to add to the bug report once it's filed? For now, I can search and replace these out to move forward.