📜  门|门CS 2010 |第 65 题

📅  最后修改于: 2021-09-24 05:22:12             🧑  作者: Mango

语法 S → aSa |乙|是
(A) LL(1) 但不是 LR(1)
(B) LR(1) 但不是 LR(1)
(C) LL(1) 和 LR(1)
(D)既不是 LL(1) 也不是 LR(1)答案: (C)
解释:

First(aSa) = a
First(bS) = b
First(c) = c
All are mutually disjoint i.e no common terminal 
between them, the given grammar is LL(1).

As the grammar is LL(1) so it will also be LR(1) as LR parsers are
more powerful then LL(1) parsers. and all LL(1) grammar are also LR(1)
So option C is correct. 

以下是更多详细信息。

如果可以通过仅查看输入字符串的下一个标记来选择下一个产生式,则语法是 LL(1)。

Formally, grammar G is LL(1) if and only if 
   For all productions  A → α1 |  α2 | ... | αn, 
      First(αi) ∩ First(αj) =  ∅, 1 ≤ i,j  ≤ n,  i ≠ j.
   For every non-terminal A such that First(A) contains ε, 
      First(A) ∩ Follow(A) = ∅ 

来源:https://s3-ap-southeast-1.amazonaws.com/erbuc/files/4147_870334aa-9922-4f78-9c2c-713e7a7f0d53.pdf
这个问题的测验