Antlr 错误“字符处没有可行的替代方案”
我正在使用 此处 提供的 Objective C 语法,并尝试解析此代码:
int main()
{
int k=0;
}
这是一个客观的 C 代码,应该对其进行解析,但是当我调用函数 Translation_unit 时,它给了我以下错误。 错误是:
line 1:0 no viable alternative at character 'main'
line 1:0 no viable alternative at character '('
line 1:0 no viable alternative at character ')'
I am using the Objective C grammar available here, and trying to parse this code:
int main()
{
int k=0;
}
this is an objective c code and it should get parsed but it is giving me the following errors when i call the function translation_unit.
errors are :
line 1:0 no viable alternative at character 'main'
line 1:0 no viable alternative at character '('
line 1:0 no viable alternative at character ')'
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
它出错是因为规则
direct_declarator
:要求
main
函数的括号内应该有一些东西。但如果你将其设为可选:我很确定会出现其他问题。坦率地说,这个语法非常糟糕:如果我是你,我就不会使用它。不,我不知道还有更好的:)。因为语法发布在 antlr-site 上并不意味着它是正确的语法。它发布在 Wiki 上,任何人都可以发布他们的作品:在使用其中的内容时请记住这一点。
It goes wrong because the rule
direct_declarator
:mandates that there should be something inside the parenthesis of the
main
function. But if you make that optional:I am pretty sure other problems will arise. To be frank, that grammar is pretty lousy: I wouldn't use it if I were you. And no, I don't know of a better one :). Because the grammar is posted on the antlr-site does not mean it's a proper grammar. It's posted on the Wiki where anyone can post their work: keep that in mind when using stuff from it.