help-bison
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Force bison syntax error on string constant


From: Hans Aberg
Subject: Re: Force bison syntax error on string constant
Date: Fri, 24 Oct 2014 16:13:07 +0200

> On 24 Oct 2014, at 15:10, Bob Rossi <address@hidden> 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.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]