语法S→aSa | bS | c是
(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
这个问题的测验