没有跟随字符串的左递归
Left recursion without following string
我对维基百科有以下两个定义:
Left recursion
A grammar is left-recursive if and only if there exists a nonterminal
symbol A that can derive to a sentential form with itself as the
leftmost symbol. Symbolically,
A ⇒ Aα where ⇒ indicates the operation of making one or more substitutions, and α is any sequence of terminal and nonterminal symbols.
和
Direct left recursion
Direct left recursion occurs when the definition can be satisfied with only one substitution. It requires a rule of the form A ⇒ Aα where α is a sequence of nonterminals and terminals,
https://en.wikipedia.org/wiki/Left_recursion
还有一个例子:
S → AB
A → B | ab | abc
B → A | d | cd
不是左递归本身,更多的是α。 α 可以是空词(作为终结符)还是空字符串?在我发现的所有间接左递归的例子中,总有一个像
这样的α
A→Bab 或
B→Ab
但我不确定如何争论,如果 A → B 和 B → A(所以没有任何 α 跟随)。它仍然是定义上的左递归吗?
α 可以是任何终结符和非终结符序列,包括空序列。
然而,A → A
形式的产生式是没有意义的。更糟糕的是,它会产生歧义,因为它可以在推导中应用任意多次,因此无法确定地解析语法。如果存在循环间接推导(A ⇒ A
在您的符号中),这同样适用。这就是为什么您很少在示例中找到此类情况的原因。但它们仍然肯定是左递归的。 (它们也是右递归的。)
单元制作(A → B
其中 A 和 B 不同)很常见,应该不会有问题。显然,在分析语法时需要考虑它们。但我不认为这是你的问题。
我对维基百科有以下两个定义:
Left recursion
A grammar is left-recursive if and only if there exists a nonterminal symbol A that can derive to a sentential form with itself as the leftmost symbol. Symbolically, A ⇒ Aα where ⇒ indicates the operation of making one or more substitutions, and α is any sequence of terminal and nonterminal symbols.
和
Direct left recursion
Direct left recursion occurs when the definition can be satisfied with only one substitution. It requires a rule of the form A ⇒ Aα where α is a sequence of nonterminals and terminals,
https://en.wikipedia.org/wiki/Left_recursion
还有一个例子:
S → AB
A → B | ab | abc
B → A | d | cd
不是左递归本身,更多的是α。 α 可以是空词(作为终结符)还是空字符串?在我发现的所有间接左递归的例子中,总有一个像
这样的αA→Bab 或 B→Ab
但我不确定如何争论,如果 A → B 和 B → A(所以没有任何 α 跟随)。它仍然是定义上的左递归吗?
α 可以是任何终结符和非终结符序列,包括空序列。
然而,A → A
形式的产生式是没有意义的。更糟糕的是,它会产生歧义,因为它可以在推导中应用任意多次,因此无法确定地解析语法。如果存在循环间接推导(A ⇒ A
在您的符号中),这同样适用。这就是为什么您很少在示例中找到此类情况的原因。但它们仍然肯定是左递归的。 (它们也是右递归的。)
单元制作(A → B
其中 A 和 B 不同)很常见,应该不会有问题。显然,在分析语法时需要考虑它们。但我不认为这是你的问题。