RELOP可以是 。== | != | < | > | <= | >=
&我在bison里有这个规则,应该可以识别。
𝐸𝑥𝑝 → 𝐸𝑥𝑝 𝑅𝐸𝐿𝑂𝑃 𝐸𝑥𝑝
这是LEX文件夹中的一部分代码。
= {return ASSIGN;}
[<=|>=] {return RELOP1;}
[<|>] {return RELOP3;}
这是我的ypp文件夹中的代码。
%right ASSIGN
%left RELOP2
%left BINOP2
%nonassoc RELOP1
%nonassoc RELOP3
Exp: Exp RELOP1 Exp { output::printProductionRule(46);}
| Exp RELOP3 Exp { output::printProductionRule(46);}
| Exp RELOP2 Exp { output::printProductionRule(46);}
这是测试。
int bar() {
if (bar <= bar >= bar) {
print("Then you got your associativity wrong");
}
}
正如你在所附的截图中看到的,bison在做reduce之前识别了IF中的第一个'<='(RELOP1),但第二次它只识别了assign!这是什么原因呢?bison
谢谢你:)