> On 24 Oct 2014, at 15:10, Bob Rossi <b...@brasko.net> wrote:
> 
> Hi,
> 
> I have a rule like this,
> 
>  output: output_variant NEWLINE {
>    *gdbmi_output = $1;
>  };
> 
>  output: error NEWLINE {
>    yyerrok;
>  };
> 
>  output_variant: OPEN_PAREN variable CLOSED_PAREN {
>    $$ = gdbmi_output_alloc();
>    $$->kind = GDBMI_OUTPUT_PROMPT;
>    free($2);
>  }
> 
> Where OPEN_PAREN is (, variable is [a-zA-Z]+ and CLOSED_PAREN is ).
> I want ONLY "gdb" to be allowed in this variable context.

If you mean that the only value that ‘variable’ can have here is “gdb”, one way 
to implement it is with a lookup table with token values. The lexer rule 
[a-zA-Z]+ checks this table to see if the name has been defined, and if “gdb” 
is there it may return a token value say GDB. The rule then becomes
  output_variant: OPEN_PAREN GDB CLOSED_PAREN

> Is there a way to force the syntax error in the action in such a way
> that bison then bubbles up the error into the above 'output' error rule?

Then the error in this context will be passed up to the right rule. It is also 
easy to switch context in a deterministic (non-GLR) parser.


_______________________________________________
help-bison@gnu.org https://lists.gnu.org/mailman/listinfo/help-bison

Reply via email to