简体   繁体   English

为以下语言创建下推自动机

[英]Create a pushdown automata for the following language

So I was doing practice problems in my book and I spotted this question. 因此,我在书中遇到练习问题,发现了这个问题。 Construct an npda accepting the language L on sigma(a,b,c). 构造一个在sigma(a,b,c)上接受语言L的npda。

L={w: number of a= number of b+1} L = {w:a的数量= b + 1的数量}

so I am interpreting it as it accepts all strings that has one more a then the letter b. 所以我正在解释它,因为它接受的所有字符串再加上一个a和一个字母b。 I believe that all the states should have a loop that has a transition (c,landa, landa) since we do not really care about the c's. 我认为所有州都应该有一个具有过渡的循环(c,landa,landa),因为我们并不真正在乎c。 After this I get really confused because there are so many cases to cover since the placement of a's and b's are arbitrary. 之后,我真的很困惑,因为要覆盖的情况太多,因为a和b的放置是任意的。 What is the way to get this problem figured out? 解决这个问题的方法是什么? Thanks!! 谢谢!!

A PDA can use a stack to remember arbitrary amounts of information. PDA可以使用堆栈来记住任意数量的信息。 This makes PDAs infinitely more capable than finite automata. 这使得PDA比有限自动机具有无限的功能。 The key to determining the PDA is figuring out how the stack will be used and then building a PDA around that. 确定PDA的关键是弄清楚如何使用堆栈,然后围绕它构建PDA。

How can we use a stack to ensure the number of a s is equal to the number of b s, plus one? 我们如何使用堆栈来确保a的数量等于b的数量加1? Well, the stack can easily keep track of the running balance of symbols that have been seen. 好了,堆栈可以轻松地跟踪已经看到的符号的运行平衡。 For instance, if we have seen four a s and two b s, our stack might represent this fact by containing aaZ , where Z is the "bottom of stack" symbol. 例如,如果我们看到四个a s和两个b s,则我们的堆栈可以通过包含aaZ来表示这一事实,其中Z是“堆栈底部”符号。 Of course, there are other methods we might use and other representations, but this is a particularly neat one for this class of problem. 当然,我们可能会使用其他方法和其他表示形式,但这对于此类问题特别整洁。 To fully explain the representation: 要完全解释该表示形式:

  1. The stack is initially Z , just the bottom of stack symbol. 堆栈最初是Z ,只是堆栈符号的底部。
  2. If we see an a and the top of the stack is a or Z , we add another a . 如果看到a ,而堆栈顶部是aZ ,则添加另一个a
  3. If we see an a and the top of the stack is b , we remove one b . 如果看到a且堆栈的顶部是b ,则删除一个b
  4. If we see a b and the top of the stack is b or Z , we add another b . 如果我们看到b并且堆栈的顶部是bZ ,则添加另一个b
  5. If we see a b and the top of the stack is a , we remove one a . 如果看到b ,而堆栈的顶部是a ,则删除a
  6. If we see a c , leave the stack alone. 如果看到c ,则不理会堆栈。

If we do this over and over again for all the input, then the content of the stack will be equal to x^m , where x is whichever of a and b occurs more frequently, and m is the absolute value of the difference of the numbers of each symbol. 如果我们对所有输入一遍又一遍地执行此操作,则堆栈的内容将等于x^m ,其中xab出现的频率更高,并且m是该n的差的绝对值每个符号的编号。

To accept your language, you must simply recognize the case where the input is exhausted and the stack consists is equal to aZ . 要接受您的语言,您必须简单地识别输入已用尽且堆栈组成等于aZ This can be done by adding some state(s) and lambda/epsilon transitions to clear the stack and/or enter an accepting state. 这可以通过添加一些状态和lambda / epsilon转换来清除堆栈和/或进入接受状态来完成。

Thanks to Peter Leupold for pointing out that the rest of the original answer got the grammar wrong. 感谢Peter Leupold指出,原始答案的其余部分都使语法错误。 I made an attempt to fix it and didn't like how long the answer was getting, so I omitted that. 我尝试修复它,不喜欢答案能得到多长时间,因此我省略了它。 I will simply add that another possibility is to produce a CFG for a language and use an algorithm to derive a PDA for it. 我将简单地补充说,另一种可能性是为一种语言生成CFG,并使用一种算法为其衍生PDA。 In this case, for me, giving the PDA directly was a lot less wordy. 在这种情况下,对我来说,直接给PDA少了很多麻烦。

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

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