I got the following flex and bison code which I want to compile and run:
unari.lex:
%{
#include "unari.tab.h"
using namespace std;
%}
%option noyywrap
%%
a {yylval=1; return TOK_A;}
\n return '\n';
\+ return '+';
. /*ignore all rest*/
%%
unari.y:
%{
#include <iostream>
using namespace std;
void yyerror(const char *errorinfo);
int yylex();
%}
%left TOK_A
%left '+'
%%
line: exp '\n' {cout<<$1<<endl; return 0;}
;
exp: exp exp {$$=$1+$2;}
| exp '+' exp {$$=$1+$3;}
| TOK_A {$$=yylval;}
;
%%
void yyerror(const char *errorinfo) {
cout<<"problem"<<endl;
}
int main() {
while(yyparse()==0);
return 0;
}
makefile:
calc: lex.yy.o unari.tab.o
g++ unari.tab.o lex.yy.o -o calc.exe
unari.tab.o: unari.tab.c
g++ -c unari.tab.c
lex.yy.o: lex.yy.c
g++ -c lex.yy.c
lex.yy.c: unari.lex unari.tab.h
flex unari.lex
unari.tab.c unari.tab.h: unari.y
bison -d unari.y
clean:
rm *.h *.c *.o *.exe
The problem is, I get the following error when compiling on windows:
makefile1:: *** multiple target patterns. Stop.
Does anyone recognizes the problem? I'm breaking my head over this for more than 3 hours already, tried searching the web and found nothing useful....
makefile1
? Or did you type the error message incorrectly? Normally it would startmakefile:[linenumber]:
where[linenumber]
is the number of the erroneous line (which would be useful to know).multiple target patterns
is only produced (as far as I know) if you have a static rule with more than one target pattern. Static rules have two:
's, and I don't see any such rule in your makefile. – rici