How to determine whether a language is LL(1) LR(0) SLR(1)

前端 未结 7 1539
暗喜
暗喜 2020-12-08 07:56

Is there a simple way to determine whether a grammar is LL(1), LR(0), SLR(1)... just from looking on the grammar without doing any complex analysis?

For instance: To

7条回答
  •  星月不相逢
    2020-12-08 08:28

    Straight from the book "Compilers: Principles, Techniques, & Tools" by Aho, et. al.

    Page 223:

    A grammar G is LL(1) if and only if whenever A -> alpha | beta are two distinct productions of G, the following conditions hold:

    1. For no terminal "a" do both alpha and beta derive strings beginning with "a"
    2. At most one of alpha and beta can derive the empty string
    3. If beta can reach the empty transition via zero or more transitions, then alpha does not derive any string beginning with a terminal in FOLLOW(A). Likewise, if alpha can reach the empty transition via zero or more transitions, then beta does not derive any string beginning with a terminal in FOLLOW(A)

    Essentially this is a matter of verifying the grammar passes the Pairwise Disjointness Test and also does not involve Left Recursion. Or more succinctly a grammar G that is left-recursive or ambiguous cannot be LL(1).

提交回复
热议问题