0
S → aSab | ABB | BB

A → baab | BABB | AaA

B → bAaBa | bb | b

I started solving it but it seems I just kept on adding new rules to keep up, can someone please explain how to do this one.

4

1 回答 1

1

这是乔姆斯基范式的结果文法:
分别由一组非终结符号、一组终结符号、规则和开始符号的 4 元组定义。

G = ({S,A,B,<Sab>,<ab>,<BB>,<aab>,<ABB>,<aA>,<AaBa>,<aBa>,<Ba>,a',b '},{a,b},R,S)

R =
S → a'<Sab> | A<BB> | BB
A → b'<aab> | B<ABB> | A<aA>
B → b'<AaBa> | b'b' | b
<Sab> → S<ab>
<ab> → a'b'
<BB> → BB
<aab> → a'<ab>
<ABB> → A<BB>
<aA> → a'A
<AaBa> → A<aBa>
<aBa> → a'<Ba>
<Ba> → Ba'
a' → a
b' → b

随意用一个字符的大写符号重命名尖括号 <> 中的非终结符(它们确实意味着单个非终结符),我觉得这更合适。

于 2015-05-01T13:11:36.427 回答