转移/减少与 SableCC 的冲突
我第一次体验 SableCC 和语法定义。 我有以下语法(其中一部分):
query =
{atop} attroperator |
{query_par} l_par query r_par |
{query_and} [q1]:query logic_and [q2]:query |
{query_or} [q1]:query logic_or [q2]:query |
{query_not} logic_not query ;
我有以下错误:
shift/reduce conflict in state [stack: PCommand TLogicNot PQuery *] on
TRPar in {
[ PQuery = PQuery * TRPar ] (shift),
[ PQuery = TLogicNot PQuery * ] followed by TRPar (reduce)
}
shift/reduce conflict in state [stack: PCommand TLogicNot PQuery *] on
TLogicAnd in {
[ PQuery = PQuery * TLogicAnd PQuery ] (shift),
[ PQuery = TLogicNot PQuery * ] followed by TLogicAnd (reduce)
}
shift/reduce conflict in state [stack: PCommand TLogicNot PQuery *] on
TLogicOr in {
[ PQuery = PQuery * TLogicOr PQuery ] (shift),
[ PQuery = TLogicNot PQuery * ] followed by TLogicOr (reduce)
}
我通过将 l_par 和 r_par 添加到所有替代方案中来解决它们,通过 方式,应该增加可读性,但是有没有办法以一种方式做到这一点 优雅的举止?
谢谢。
I'm at my first experience with SableCC and grammar definition.
I have the following grammar (a part of it):
query =
{atop} attroperator |
{query_par} l_par query r_par |
{query_and} [q1]:query logic_and [q2]:query |
{query_or} [q1]:query logic_or [q2]:query |
{query_not} logic_not query ;
I have the following errors:
shift/reduce conflict in state [stack: PCommand TLogicNot PQuery *] on
TRPar in {
[ PQuery = PQuery * TRPar ] (shift),
[ PQuery = TLogicNot PQuery * ] followed by TRPar (reduce)
}
shift/reduce conflict in state [stack: PCommand TLogicNot PQuery *] on
TLogicAnd in {
[ PQuery = PQuery * TLogicAnd PQuery ] (shift),
[ PQuery = TLogicNot PQuery * ] followed by TLogicAnd (reduce)
}
shift/reduce conflict in state [stack: PCommand TLogicNot PQuery *] on
TLogicOr in {
[ PQuery = PQuery * TLogicOr PQuery ] (shift),
[ PQuery = TLogicNot PQuery * ] followed by TLogicOr (reduce)
}
I solved them by adding l_par and r_par to all alternatives which, by the
way, should increase readability but is there a way to do it in an
elegant manner?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
所以,我已经解决了这个问题。我所做的基本上定义了三个级别的关联性。
这是经典的结合性方案 +,* 和一元运算符,例如 - 其中
+ =logic_or
、* =logic_and
、- =logic_not
。So, I've solved the problem. What I've done is basically define three levels of associativity.
It's the classic associativity scheme +,* with an unary operator like - where
+ = logic_or
,* = logic_and
,- = logic_not
.