I'm in the process of creating a compiler for a relatively simple language using Flex and Bison on Windows. However the compiler is telling me thatthe functions yyerror and yyparse weren't declared in the right scope. After some reading I found out that the problem is apparently conflicting C and C++ linkage (I'm using g++ as I'm trying to build an abstract syntax tree). Code excerpts below.
monty.y:
%{
extern "C" {
int yyparse();
int yylex(void);
void yyerror(char *s){}
int yywrap(void){return 1;}
}
#include <stdio.h>
#include <string.h>
#include "ast\ast.h"
using namespace std;
Program* root;
//extern int yyparse();
main() {
yyparse();
}
%}
monty.l:
%{
#include <stdlib.h>
#include "ast/ast.h"
#include "y.tab.h"
%}
%%
"do" { puts("DO"); return DO; }
"else" { puts("ELSE"); return ELSE; }
"end" { puts("END"); return END; }
"if" { puts("IF"); return IF; }
etc...
%%
int main(void)
{
yyparse();
return 0;
}
Any help or enlightenment as to the source of these errors would be greatly appreciated :)