bug-bison
[Top][All Lists]
Advanced

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

Re: yyparse being prototyped in y.tab.h causes problems.


From: Akim Demaille
Subject: Re: yyparse being prototyped in y.tab.h causes problems.
Date: Tue, 18 Aug 2015 11:06:56 +0200

> Le 14 août 2015 à 18:14, Kaz Kylheku <address@hidden> a écrit :

Hi Kaz,

> Simple two-file test case:
> 
> /* parser.y ----------------- */
> %{
> 
> #include <stdio.h>
> 
> typedef struct {
>  int dummy;
> } private_context;
> 
> %}
> 
> %pure-parser
> %parse-param{private_context *ctx}
> 
> %union {
>  char *str;
> }
> 
> %token<str> TOK
> %type<str> start
> 
> 
> %%
> 
> start : TOK { $$ = $1; }
> 
> %%
> 
> int public_parse_wrapper(void)
> {
>  private_context pc;
>  return yyparse(&pc);
> }
> 
> /* lexer.c ----------------------- */
> #include "y.tab.h"
> 
> int yylex(YYSTYPE *yylval)
> {
>   yylval->str = "foo";
>   return TOK;
> }
> 
> If we translate parser.y with "bison --yacc -d" to generate a y.tab.h and 
> y.tab.c,
> the y.tab.h contains:
> 
>  int yyparse (private_context *ctx);

I think that adding

%code requires
{
  struct private_context;
}

should suffice to address your concern.  This will add this forward definition 
before the declaration of yyparse in the header.


reply via email to

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