Antlr 非 LL(*) 决策
我在为我的编程语言创建部分 ANTLR 语法时遇到一些问题。
当 type
声明的第二部分发生时,我收到错误:
public type
: ID ('.' ID)* ('?')? -> ^(R__Type ID ID* ('?')?)
| '(' type (',' type)* ')' ('?')? -> ^(R__Type type* ('?')?)
;
我尝试匹配:
- 像
System.String
这样的行(工作正常) - 元组例如
(System.String, System.Int32)
错误发生在树的稍上方,并指出:
[fatal] 规则语句由于递归规则而具有非 LL(*) 决策可从 alts 进行调用1,2。通过左因子分解或使用语法谓词或使用 backtrack=true 选项来解决。
我做错了什么?
I'm having some trouble creating part of my ANTLR grammar for my programming language.
I'm getting the error when the second part of the type
declaration occurs:
public type
: ID ('.' ID)* ('?')? -> ^(R__Type ID ID* ('?')?)
| '(' type (',' type)* ')' ('?')? -> ^(R__Type type* ('?')?)
;
I'm trying to either match:
- A line like
System.String
(works fine) - A tuple such as
(System.String, System.Int32)
The error occurs slightly higher up the tree, and states:
[fatal] rule statement has non-LL(*) decision due to recursive rule invocations reachable from alts 1,2. Resolve by left-factoring or using syntactic predicates or using backtrack=true option.
What am I doing wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的,我通过编辑处理变量声明的规则,设法在树的早期修复了这个问题:
这样它的工作方式如下:
我从这里的语法谓词示例中得到了这个想法:
https://wincent.com/wiki/ANTLR_predicates
幸运的是我最终不需要谓词!
Right, I managed to fix this a little earlier up the tree, by editing the rule that deals with variable declarations:
So that it works like:
I got the idea from the example of syntactic predicates here:
https://wincent.com/wiki/ANTLR_predicates
Luckily I didn't need a predicate in the end!