生产中可选的非终端
有谁知道以下情况如何处理?
if-section:
if-group [ elif-groups ] [ else-group ] endif-line
if-group:
....
elif-groups:
elif-group
elif-groups elif-group
elif-group:
"#" "elif" constant-expression new-line [ group ]
else-group:
"#" "else" new-line [ group ]
endif-line:
"#" "endif" new-line
if-group 后的 if-section 中的所有非终结符均以“#”开头。我认为在这种情况下,左因式分解是不可能的。是否有任何“默认解决方案”来确定我是否必须调用两个(或两个)可选非终端之一?
谢谢。
Does anyone know how to handle the following case?
if-section:
if-group [ elif-groups ] [ else-group ] endif-line
if-group:
....
elif-groups:
elif-group
elif-groups elif-group
elif-group:
"#" "elif" constant-expression new-line [ group ]
else-group:
"#" "else" new-line [ group ]
endif-line:
"#" "endif" new-line
All non-terminals in if-section after if-group starting with "#". I think in this case there is left-factoring impossible. Are there any "default solutions" to identify if I have to call one of the both (or both) optional non-terminals?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不清楚需要处理什么。当您只看到
#
时,您无法区分[ elif-groups ]
和[ else-group ]
,不。但如果你向前看另一个令牌,你就可以。即两个令牌足以决定。到目前为止,这还不是 C++ 语法中最糟糕的部分。
I'm unclear what needs handling. You can't distinguish between
[ elif-groups ]
and[ else-group ]
when you've seen just#
, no. But if you look ahead another token, you can. I.e. two tokens is enough to decide.This isn't the worse bit of C++ grammar by far.