I am trying to make a small interpreter using Flex and Bison.
Now I have two files: parser.l
and parser.y
. Usually, main function is put in parser.y
file. What I want to do is to put the main function in a different file main.cpp
which makes my package look neat.
#include "y.tab.h"
int main()
{
yyparse();
return 0;
}
But when I compile, I got an error:
undefined reference to `main'
So I know there is something wrong to include y.tab.h
.
Could you someone to tell me how to do it?
Solution
I just figured it out: add the following to your main.c file:
extern FILE *yyin;
extern FILE *yyout;
extern int yyparse(void);