操作precedence在boost ::精神? [英] Operator precedence in boost::spirit?
问题描述
我用做精神mini_c样品一些测试。遗憾的是它并没有保持运营precedence预期:
I made some tests using the spirit mini_c sample. Unfortunately it does not keep the operator precedence as expected:
int main()
{
return 3 > 10 || 3 > 1;
}
计算结果为0。
return (3 > 10) || (3 > 1);
返回1
我试着动||的定义和与&&放大器;在的构造函数
I tried to move the definition of "||" and "&&" to the very top in the constructor of
template <typename Iterator>
expression<Iterator>::expression(
但是,这并不能改变什么。那怎么可以修复。我使用的提振38年3月1日。
but that does not change anything. How can that be fixed. I am using boost 1.3.38.
推荐答案
确认,这是在与运营商precedence的mini_c例子中的错误。我犯了一个修复程序SVN,这将是加速V1.45可用。以下是我在头文件mini_cb.hpp改变:
Confirmed, that's a bug in the mini_c example related to operator precedence. I committed a fix to SVN, which will be available in Boost V1.45. Here is what I changed in the header file mini_cb.hpp:
老code:
equality_expr =
relational_expr
>> *( ("==" > relational_expr [op(op_eq)])
| ("!=" > relational_expr [op(op_neq)])
)
;
relational_expr =
logical_expr
>> *( ("<=" > logical_expr [op(op_lte)])
| ('<' > logical_expr [op(op_lt)])
| (">=" > logical_expr [op(op_gte)])
| ('>' > logical_expr [op(op_gt)])
)
;
logical_expr =
additive_expr
>> *( ("&&" > additive_expr [op(op_and)])
| ("||" > additive_expr [op(op_or)])
)
;
新的code:
equality_expr =
logical_expr
>> *( ("==" > logical_expr [op(op_eq)])
| ("!=" > logical_expr [op(op_neq)])
)
;
logical_expr =
relational_expr
>> *( ("&&" > relational_expr [op(op_and)])
| ("||" > relational_expr [op(op_or)])
)
;
relational_expr =
additive_expr
>> *( ("<=" > additive_expr [op(op_lte)])
| ('<' > additive_expr [op(op_lt)])
| (">=" > additive_expr [op(op_gte)])
| ('>' > additive_expr [op(op_gt)])
)
;
这篇关于操作precedence在boost ::精神?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!