如何消除 ANTLR3 语法中的以下多个替代警告?
[11:45:19] warning(200): mygrammar.g:14:57: Decision can match input such as "','" using multiple alternatives: 1, 2
As a result, alternative(s) 2 were disabled for that input
[11:45:19] warning(200): C:\Users\Jarrod Roberson\mygrammar.g:14:57: Decision can match input such as "','" using multiple alternatives: 1, 2
As a result, alternative(s) 2 were disabled for that input
我希望能够将函数嵌套在其他函数中。
myfunction(x) ->
sqr(a) -> a * a,
y -> sqr(x).
这是它抱怨的行
function : ID '(' args ')' '->' statement (',' statement)* ;
,这是它正在考虑的替代方案,
statement : ATOM
| expression
| assignment
| function
;
我使用 .
作为我的语句结束规则
program : (statement'.')*;
这是 ANTLRWorks 中的 synatx 图的样子
(来源:vertigerated.com)
我真的很喜欢东西编译/工作时没有任何警告。如何解决此警告情况?
[11:45:19] warning(200): mygrammar.g:14:57: Decision can match input such as "','" using multiple alternatives: 1, 2
As a result, alternative(s) 2 were disabled for that input
[11:45:19] warning(200): C:\Users\Jarrod Roberson\mygrammar.g:14:57: Decision can match input such as "','" using multiple alternatives: 1, 2
As a result, alternative(s) 2 were disabled for that input
I want to be able to nest functions inside other functions.
myfunction(x) ->
sqr(a) -> a * a,
y -> sqr(x).
here is the line it is complaining about
function : ID '(' args ')' '->' statement (',' statement)* ;
and here is what it is considering the alternative
statement : ATOM
| expression
| assignment
| function
;
I am using .
as my statement end rule
program : (statement'.')*;
Here is what the synatx diagram looks like in ANTLRWorks
(source: vertigrated.com)
I really like things to compile/work without any warnings. How do I resolve this warning condition?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的解析器可以解析以下输入:
在两个不同的解析树中:
和:
您可以通过强制解析器向前查看并确保前面有
',' 语句
来解决此问题在实际匹配这些规则之前。您可以通过使用语法谓词((...)=>
部分)并在其中包含所述规则来做到这一点:但是,如果您的
函数 规则有某种“结束”标记,您尚未定义。从您之前的问题和示例来看:
您似乎正在使用
'.'
作为function
的结尾。如果您将其添加到您的function
规则中:您根本不需要谓词。
Your parser can parse the following input:
in two different parse trees:
and:
You can fix this by forcing the parser to look ahead and make sure there is
',' statement
ahead before actually matching these rules. You can do that by using a syntactic predicate (the(...)=>
part) with said rule inside:However, you don't need the predicate if your
function
rule has some sort of an "end" token, which you haven't defined. From your earlier questions, and your example:it seems you're using the
'.'
as the end of afunction
. If you add that to yourfunction
rule:you don't need a predicate at all.