简体   繁体   English

如何查找CFG生成的语言

[英]How to find the language generated by a CFG

If a Context-Free Grammar is given, is there a systematic way to find out the generated language and express it as a set using a descriptive and not analytic way, like L(G)={0^n.1^n|n?=1} (and not L(G)={01,0011,000111,...}) ? 如果给出了上下文无关的语法,是否有系统的方法找出生成的语言并使用描述性而非解析性方法将其表达为集合,例如L(G)= {0 ^ n.1 ^ n | n ?= 1}(而不是L(G)= {01,0011,000111,...})?

I actually ask because if a CFG is given and there is a question like: "Find the language of the grammar.Prove/Justify your answer." 我实际上是问,因为是否给出了CFG,并且有一个类似的问题:“找到语法的语言。证明/证明你的答案。” , then how can someone prove/justify his/her answer otherwise? ,那么别人怎么能证明/证明他/她的答案呢?

In general, no. 一般来说,没有。 For example, for an arbitrary context free grammar, the question of whether the language is equivalent to Sigma* is undecidable -- and that's about the simplest description of a CFL one might imagine. 例如,对于任意上下文无关的语法,该语言是否等效于Sigma *的问题是不确定的-这就是人们可能想到的最简单的CFL描述。 Another undecidable question is whether two context free grammars A and B define the same language, which doesn't bode well for the more general question of whether a grammar and some other alternate presentation define the same language. 另一个不确定的问题是两个上下文无关的语法A和B是否定义相同的语言,对于语法和其他替代表示形式是否定义相同的语言这一更普遍的问题而言,这并不是一个好兆头。

In specific cases, such questions may be decidable -- fortunately for formal language theory students! 在特定情况下,此类问题可能是可决定的-幸运的是,对于语言理论专业的学生! But in light of the above decidability results, you're not going to find a simple algorithm that gets you from a grammar, to a concise description of the sort usually presented in language theory textbooks. 但是,鉴于上述可判定性的结果,您不会找到一种简单的算法,可以使您从语法中获得对语言理论教科书中通常提供的那种简明描述。 It's more of a trial and error process, where you use some intuition to think up a candidate description, then apply the more formal methods like building parse trees, or using closure properties or pumping lemmas, to prove or disprove the equivalence. 它更多是一个反复试验的过程,在此过程中,您会使用一些直觉来思考候选描述,然后应用更正式的方法(例如,构建解析树,使用闭包属性或抽取引理)来证明或反对等价。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM