0

Bison is not able to resolve the user-param type in *.tab.hpp.

Bison version:

GNU Bison 2.7.

.l file:

{
#include<stdio.h>
#include <string.h>
#include <stdlib.h>
#include <malloc.h>
#include <errno.h>
#include "pinMapTab.h"
extern int errno;

%}
%option nounput
%option noinput

%%
"="                    { return EQUALS; }
","                    { return COMMA; }
";"                    { return SEMICOLON; }
PORT                   { return PORT; }
PIN                    { return PIN; }
PACKAGE                { return PACKAGE; }
[a-zA-Z_][a-zA-Z0-9_]* {yylval.str =strdup(yytext);return ALPHANUMERIC;}
[a-zA-Z_][a-zA-Z0-9_]*\[[0-9]*\] {yylval.str =strdup(yytext);return BUS_PORT;}
[0-9_]*                 {yylval.str = strdup(yytext);return NUMBER;}
"//".* | [\t]          {; }
"/*"[.\n]*"*/"         {; }
\n                     {; }
.                      {; }
%%

int yywrap()
{
   return 1;
}

.y file:

%{

#include <stdio.h>
#include <stdarg.h>
#include <iostream>
#include <ostream>
#include <string>

#include <pinMapParser.h>
 
namespace dc {
  class pinMapParser; 
}
#undef YYLMAX
#define YYLMAX 100000
extern int lineno;
extern "C" int yywrap();
int yyerror(dc::pinMapParser *pm,std::string msg);
extern "C" char yytext[];
extern "C" int yylex();
%}

%parse-param {dc::pinMapParser *pm} 

%union
{
   int val;
   char *str; 
}

….  //parsing grammer

int yyerror(dc::pinMapParser *pm, std::string msg)
{
  return 1;
}

Bison generated .hpp

ifndef YY_YY_PINMAP_TAB_HPP_INCLUDED
# define YY_YY_PINMAP_TAB_HPP_INCLUDED
/* Enabling traces.  */
#ifndef YYDEBUG
# define YYDEBUG 0
#endif
#if YYDEBUG
extern int yydebug;
#endif

/* Tokens.  */
#ifndef YYTOKENTYPE
# define YYTOKENTYPE
   /* Put the tokens into the symbol table, so that GDB and other debuggers
      know about them.  */
   enum yytokentype {
     EQUALS = 258,
     COMMA = 259,
     SEMICOLON = 260,
     PACKAGE = 261,
     PIN = 262,
     PORT = 263,
     ALPHANUMERIC = 264,
     BUS_PORT = 265,
     NUMBER = 266
   };
#endif

#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
typedef union YYSTYPE
{
/* Line 2058 of yacc.c  */
#line 25 "pinMap.ypp"

   int val;
   char *str;


/* Line 2058 of yacc.c  */
#line 74 "pinMap.tab.hpp"
} YYSTYPE;
# define YYSTYPE_IS_TRIVIAL 1
# define yystype YYSTYPE /* obsolescent; will be withdrawn */
# define YYSTYPE_IS_DECLARED 1
#endif

extern YYSTYPE yylval;

#ifdef YYPARSE_PARAM
#if defined __STDC__ || defined __cplusplus
int yyparse (void *YYPARSE_PARAM);
#else
int yyparse ();
#endif
#else /* ! YYPARSE_PARAM */
#if defined __STDC__ || defined __cplusplus
int yyparse (dc::pinMapParser *pm);
#else
int yyparse ();
#endif
#endif /* ! YYPARSE_PARAM */

#endif /* !YY_YY_PINMAP_TAB_HPP_INCLUDED  */

Problem: As you can see the prototype of yyparse in generated .hpp includes dc::pinMapParser but its header file is not being included. I'm seeing compiler errors because of this problem.

int yyparse (dc::pinMapParser *pm);

Error:

In file included from pinMap.l:7:
pinMap.tab.hpp:90:23: error: expected ‘)’ before ‘:’ token
   90 | int yyparse (dc::pinMapParser *pm);
      |                       ^   
      |                       )   
*** exit status 1 *** 
kiran Biradar
  • 12,700
  • 3
  • 19
  • 44
  • 1
    Your problem is in your flex file, not your bison file. You either need to #include pinMapParser.h before you include the bison header, or use a [`%code requires`](https://www.gnu.org/software/bison/manual/html_node/_0025code-Summary.html) block in your bison file to insert the include into the header file produced by bison. – rici Dec 02 '20 at 06:44
  • @rici What if I don't want prototype of `yyparse` to be part of header file produced by bison, surprisingly in `bison 2.4` prototypes of `yyparse` were actually part of `cpp` produced by bison. – kiran Biradar Dec 02 '20 at 07:11
  • I don't think there's any option to suppress the declaration of `yyparse`. – rici Dec 02 '20 at 13:10
  • @rici I was able to resolve per your suggestion, Thank you. – kiran Biradar Dec 02 '20 at 13:15

0 Answers0