由于递归规则调用,规则具有非 LL(*) 决定 [英] rule has non-LL(*) decision due to recursive rule invocations
问题描述
我有一个错误(如标题中所述),其中包含一条我不知道如何解决的规则.
I have an error (like said in the title) with one rule that i dont know how resolve.
我写了以下规则:
FunctionArguments returns FunctionArgs::IFunctionArguments :
FunctionArgumentsNormal
| FunctionArgumentsForIter
;
FunctionArgumentsNormal returns FunctionArgs::IFunctionArguments :
{FunctionArgs::FunctionArguments} args+=Expression (',' args+=Expression)*
| {FunctionArgs::FunctionArguments} argNames+=NamedArguments (',' argNames+=NamedArguments)*
;
FunctionArgumentsForIter returns FunctionArgs::IFunctionArguments :
{FunctionArgs::FunctionArgumentsIterator} exp=Expression 'for' iterators=ForIterator
;
您能帮我解决这个表达式的左因子问题吗?或者请提供任何其他解决方案吗?
Could you help me to resolve it by left-factoring this expression or give any others solutions please ?
推荐答案
在 LL 语法中,您不能有左递归.问题是 LL 解析器可以选择进行这样的推导:FunctionArguments -> FunctionArgumentsNormal -> FunctionArguments -> FunctionArgumentsNormal ...您的语法包含所谓的间接左递归.您可以在此维基百科文章中找到一个示例,其中还包含有关如何修复它的解决方案:Left-递归.一个好的起点是(我想您已经这样做了)以非常简单的方式编写语法,而无需示例中包含的所有注释和内容.如果你有简单形式的语法:
In a LL grammar you can have no left-recursion. The problem is that a LL parser can choose to make a derivation like this: FunctionArguments -> FunctionArgumentsNormal -> FunctionArguments -> FunctionArgumentsNormal ... Your grammar contains what is called indirect left recursion. You can find an example in this wikipedia-article which also contains a solution as to how you can fix it: Left-Recursion. A good place to start is by (I suppose you already have done this) writing your grammar in a very simple way without all the annotations and things included in your example. If you have the grammar on the simple form:
S -> A | B
B -> "terminal1" B
| b
A -> a "terminal2"
进行必要的重写要容易得多.
it is much easier to do the necessary rewriting.
这篇关于由于递归规则调用,规则具有非 LL(*) 决定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!