文法不是 LL(1),即使它没有左递归或公共前缀
A grammar is not LL(1) even though it has no left recursion or common prefixes
据推测,以下语法不是LL(1)。但是我找不到原因。我认为它是完美的 LL(1),因为它没有左递归,也没有公共前缀问题。有人可以澄清一下吗?
LL(1) 意味着可以构造一个使用单个标记向前看的解析器,并且在 stmt
中,assignment
和 subr_call
都以 [=13 开头=] 所以解析器无法仅通过查看第一个标记 (ID
) 来区分这两种情况。
来自斯坦福笔记
Informally, an LL(1) has no
left-recursive productions and has been left-factored. Note that these are necessary
conditions for LL(1) but not sufficient, i.e., there exist grammars with no left-recursion or
common prefixes that are not LL(1).
所以这些是必要条件而不是充分条件。
据推测,以下语法不是LL(1)。但是我找不到原因。我认为它是完美的 LL(1),因为它没有左递归,也没有公共前缀问题。有人可以澄清一下吗?
LL(1) 意味着可以构造一个使用单个标记向前看的解析器,并且在 stmt
中,assignment
和 subr_call
都以 [=13 开头=] 所以解析器无法仅通过查看第一个标记 (ID
) 来区分这两种情况。
来自斯坦福笔记
Informally, an LL(1) has no left-recursive productions and has been left-factored. Note that these are necessary conditions for LL(1) but not sufficient, i.e., there exist grammars with no left-recursion or common prefixes that are not LL(1).
所以这些是必要条件而不是充分条件。