转换为乔姆斯基范式
我确实需要你的帮助。 我有这些产生式:
1) A--> aAb
2) A--> bAa
3) A--> ε
我应该应用乔姆斯基范式(CNF)。
为了应用上述规则,我应该:
- 消除 ε 产生式
- 消除酉产生式
- 删除无用符号
我立即陷入困境。原因是A是一个可为空的符号(ε是其主体的一部分)
当然我不能删除A符号。
谁能帮我得到最终的解决方案?
I do need your help.
I have these productions:
1) A--> aAb
2) A--> bAa
3) A--> ε
I should apply the Chomsky Normal Form (CNF).
In order to apply the above rule I should:
- eliminate ε producions
- eliminate unitary productions
- remove useless symbols
Immediately I get stuck. The reason is that A is a nullable symbol (ε is part of its body)
Of course I can't remove the A symbol.
Can anyone help me to get the final solution?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
正如 维基百科 所指出的,乔姆斯基范式有两种定义,其区别在于ε 产品的处理。您必须选择允许这些的语法,否则您将永远不会得到等效的语法:您的语法生成空字符串,而遵循其他定义的 CNF 语法则无法做到这一点。
As the Wikipedia notes, there are two definitions of Chomsky Normal Form, which differ in the treatment of ε productions. You will have to pick the one where these are allowed, as otherwise you will never get an equivalent grammar: your grammar produces the empty string, while a CNF grammar following the other definition isn't capable of that.
要开始转换为乔姆斯基范式(使用维基百科页面提供的定义 (1)),您需要找到等效的本质上非收缩语法。带有起始符号
S
的语法G
本质上是非收缩的,当且仅当调用您的语法
G
时,等效语法G'
为非递归起始符号为:显然,
G'
的可空变量集合为{S,A}
,因为A -> ε
是G'
和S -> 的产生式。 A
是链式法则。我假设您已经获得了一种从语法中删除 ε 规则的算法。该算法应该生成类似于以下的语法:语法
G''
本质上是非收缩的;现在,您可以将剩余的算法应用于语法,以找到乔姆斯基范式的等效语法。To begin conversion to Chomsky normal form (using Definition (1) provided by the Wikipedia page), you need to find an equivalent essentially noncontracting grammar. A grammar
G
with start symbolS
is essentially noncontracting iffCalling your grammar
G
, an equivalent grammarG'
with a non-recursive start symbol is:Clearly, the set of nullable variables of
G'
is{S,A}
, sinceA -> ε
is a production inG'
andS -> A
is a chain rule. I assume that you have been given an algorithm for removing ε-rules from a grammar. That algorithm should produce a grammar similar to:The grammar
G''
is essentially noncontracting; you can now apply the remaining algorithms to the grammar to find an equivalent grammar in Chomsky normal form.