You are compiling the generated files with C++, although they are C files. That generally works but there is an issue with the declaration of yylex
. In C,
int yylex();
declares yylex
as a function without specifying anything about its parameter list. (int yylex(void)
would declare it to have no parameters.) That's not possible in C++, so you need to provide the precise parameter list. Unfortunately, the code block containing the definition of yylex
is inserted into the generated code before YYLTYPE
is defined.
A simple solution is to predeclare YYLTYPE as an incomplete type:
struct YYLTYPE;
which lets you use YYLTYPE*
in the declaration of yylex
. YYLTYPE
will eventually be declared as a struct
, unless you've provided your own declaration.
With a sufficiently recent version of bison, you should be able to use the following:
%code requires {
#include <iostream>
#include <stdio.h>
/* If you insist :) */
using namespace std;
}
%code provides {
void yyerror (char const*);
int yylex (YYSTYPE*, YYLTYPE*);
extern "C" int yyparse ();
%}
(This is quite possibly not what you want for a pure parser. But it might be enough to get you started.)