【发布时间】:2013-11-12 23:54:51
【问题描述】:
我得到了以下要编译和运行的 flex 和 bison 代码:
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;
}
制作文件:
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
问题是,我在windows上编译时出现以下错误:
makefile1:: *** multiple target patterns. Stop.
有人认识到这个问题吗?我已经为此烦恼了三个多小时,尝试搜索网络并没有发现任何有用的信息....
【问题讨论】:
-
Flex 标签用于 ADobe/Apache UI 框架。 Flex-lexer 标签用于词法分析器。
-
您确定这是您的确切生成文件吗?
-
这可能是你的问题:'unari.tab.c unari.tab.h: unari.y'。通常':'后面只剩下一个单词
-
不,应该没问题……
-
makefile1是什么?还是您错误地输入了错误信息?通常它会以makefile:[linenumber]:开头,其中[linenumber]是错误行的编号(知道这一点很有用)。multiple target patterns仅在您有一个具有多个目标模式的静态规则时才会生成(据我所知)。静态规则有两个:,我在你的 makefile 中没有看到任何这样的规则。
标签: c++ c bison flex-lexer