简体   繁体   English

语言{0 ^ m 1 ^ m 2 ^ n |的结果是什么? n> = 0,m> n}

[英]What is the productions for language {0^m 1^m 2^n | n>=0, m > n}

I would like to know how to get the productions for language {0^m 1^m 2^n | 我想知道如何获得语言{0 ^ m 1 ^ m 2 ^ n | n>=0, m > n}. n> = 0,m> n}。

This is what I had which I'm not sure if it's correct. 这是我所拥有的,我不确定是否正确。 Please correct me if I'm wrong: 如果我错了,请纠正我:

 S -> 01A | 0B1A | 00B11A
 A -> 2A | 2 | λ
 B -> 01

Thank you. 谢谢。

This language is not context free. 该语言不是上下文无关的。 This can be shown using the pumping lemma for context-free languages. 对于上下文无关的语言,可以使用抽水引理来证明这一点。 You end up with five cases; 您最终遇到了五种情况; three of the cases pump only one of the symbols 0, 1 or 2; 三种情况仅泵送符号0、1或2中的一种; and two cases pump adjacent symbols. 还有两种情况会标出相邻的符号。 Note that you can almost do it except that we can choose the string 0^(p+1) 1^(p+1) 2^p and even when you span 0s and 1s and pump them evenly you still fail the m>n test when pumping down. 注意,除了我们可以选择字符串0 ^(p + 1)1 ^(p + 1)2 ^ p之外,几乎可以做到这一点,即使跨越0和1并均匀泵送它们,您仍然会失败m> n抽气时进行测试。

There are more powerful grammars than context free. 语法比上下文无关还有更强大的语法。 We can produce a general grammar for this language. 我们可以为这种语言产生一般的语法。

S -> RT
R -> 0R1X | 01

X1 -> 1X

XT -> T2 | T
1T -> e

The first two productions produce strings of the form 0^n (01) (1X)^n T. 前两个产品产生格式为0 ^ n(01)(1X)^ n T的字符串。

The third production produces strings of the form 0^n (01) 1^n X^n T. It allows the X's to "float" to the right past all the 1s. 第三生产产生形式为0 ^ n(01)1 ^ n X ^ n T的字符串。它允许X浮动到所有1之后的右边。

The last two productions produce strings of the form 0^n (01) 1^n 2^m, m<=n. 最后两个产品产生格式为0 ^ n(01)1 ^ n 2 ^ m的字符串,m <= n。 These allow the T to "float" left past the Xs, translating each X into either 2 or nothing. 这些使T可以“浮动”离开X,将每个X转换为2或不转换为零。

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

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