Determine if LL is a grammar using a pairwise disjoint test

I have three grammars:

A → aB | b | CBB

B → aB | ba | Abb

C → aaA | b | Cab

I need to "determine whether [they] are LL grammars by performing a pairwise disjoint test, showing the first sets of each RHS of each nonterminal.

This is what I still have ...

A → aB | b | CBB

first (aB) = a

first (b) = b

first (CBB) = aaA = a

This is what I came across. Am I doing the CBB right? If so, I would say that they intersect and the rule does not pass the test. (Right?)

B → aB | ba | Abb

first (aB) = a

first (ba) = b

first (aBb) = a

They intersect and therefore the rule does not pass the test.

C → aaA | b | Cab

first (aaA) = a

first (b) = b

first (caB) = c

They do not intersect and therefore the rule passes

+4
source share
2 answers

The check point is to see if, looking at the first terminal, you can specify which rule to use (requirement for LL). Its pretty obvious for B that there are 2 rules that can apply for terminal a; its also pretty obvious that every rule for C starts from a different terminal. And you can see that the possible first terminals for C (and therefore CBB) overlap for other rules for A.

Bottom line: it looks good (although if you stopped at the same terminal for CBB and accidentally chose c, you would have come to the wrong end).

+6
source

I believe that FIRST sets rules A {a}, {b} and {a, b, c}. The grammar is not LL, because it does not pass the pairwise mismatch test due to the presence of at least one intersection. In fact, in this case there are two intersecting terminals: a and b.

0
source

Source: https://habr.com/ru/post/1393648/


All Articles