osolmaz
osolmaz

Reputation: 1923

Differences between bison versions

I am new to lexical analysis and parser generation, and I tried to start directly by compiling the bison example from wikipedia. This is an example of a reentrant parser.

I tried to compile with 2 versions of bison: 2.5 and 2.6.5. The former compiles and executes perfectly, but the latter includes the type yyscan_t in the parser header which is declared in the lexer header (Lexer.h) (which I guess is required for reentrant features). Hence it does not compile Parser.c generated by Parser.y

Here is the extra part generated in Parser.h by 2.6.5 which is not present in 2.5:

#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 (SExpression **expression, yyscan_t scanner); // this line
#else
int yyparse ();
#endif
#endif /* ! YYPARSE_PARAM */

I've marked the line causing the problem. Any thoughts?

Edit: What I need to do is to ensure that yyscan_t is declared in the header file generated by bison.

Upvotes: 1

Views: 1298

Answers (1)

Cramer McBarett
Cramer McBarett

Reputation: 46

Indeed, bison since 2.6 inserts the previously mentionned block of code in the header section.

You need to tell bison to insert all the declarations of the yyparse function arguments before this block by moving a subsection of what was part of a %code {...} (or %{...%}) section into a new code section with the tag 'requires' so for it to be inserted at the top of the header, in your yy file:

%code requires {
typedef void*                 yyscan_t;
} 

See the bison fraking manual:

http://www.gnu.org/software/bison/manual/html_node/_0025code-Summary.html

http://www.gnu.org/software/bison/manual/html_node/Prologue-Alternatives.html#Prologue-Alternatives

Hope that helps

Upvotes: 3

Related Questions