Reputation: 11444
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....
Upvotes: 1
Views: 562
Reputation: 7056
Instead of
unari.tab.c unari.tab.h: unari.y
bison -d unari.y
try
unari.tab.h: unari.y
bison -d unari.y
unari.tab.c: unari.y
bison unari.y
There may be other ways to do it, but I'm pretty sure that will work for you.
Odd. I copied your files, and once I got all the spaces/tab issues worked out in the Makefile it seem to work fine.
[Charlies-MacBook-Pro:~/junk] crb% make clean
rm *.h *.c *.o *.exe
[Charlies-MacBook-Pro:~/junk] crb% make
bison -d unari.y
unari.y: conflicts: 2 shift/reduce
flex unari.lex
g++ -c lex.yy.c
g++ -c unari.tab.c
g++ unari.tab.o lex.yy.o -o calc.exe
[Charlies-MacBook-Pro:~/junk] crb% which make
/usr/bin/make
[Charlies-MacBook-Pro:~/junk] crb% make --version
GNU Make 3.81
Could be issues with make on windows, and I don't have a windows machine. Maybe try googling 'multiple target patterns. Stop.'
Upvotes: 2
Reputation: 20818
Hard to see here (or even in your editor by default) but make is very strict in regard to having tabs before comments on the following line.
foo.c foo.h: foo.lex
<tab>command
where <tab> represents the tab character. If you have spaces, then it is likely to fail.
P.S. the number of targets to the left of the colon is valid. It means that the command(s) generate all those targets at once.
http://amake.m2osw.com/amake-rules.html
Upvotes: 0