简体   繁体   English

如何构造 L={a^nb^m where n<=m<=2n} 的下推自动机?

[英]How to construct a pushdown automata for L={a^nb^m where n<=m<=2n}?

It should be constructed without using 2 stacks.它应该在不使用 2 个堆栈的情况下构建。 I tried it but I couldn't do it without 2 stacks.我试过了,但如果没有 2 个堆栈,我就无法做到。

Here's the strategy: we can easily make a PDA that accepts a^nb^n, and we can easily make one that accepts a^nb^2n.策略如下:我们可以很容易地制作一个接受 a^nb^n 的 PDA,我们也可以很容易地制作一个接受 a^nb^2n 的 PDA。 Our language is a superset of these languages that also accepts anything with a number of b in between n and 2n.我们的语言是这些语言的超集,它也接受 n 到 2n 之间的任何 b 数。 We can make use of nondeterminism to allow this as follows: for every a we put onto the stack, we can nondeterministically decide whether to consume one or two b before popping the a.我们可以利用非确定性来实现这一点,如下所示:对于我们放入堆栈的每个 a,我们可以在弹出 a 之前不确定地决定是消耗一个还是两个 b。 If our NPDA chooses to consume one each time, we get a^nb^n.如果我们的 NPDA 选择每次消耗一个,我们得到 a^nb^n。 If it choose to consume two each time, we get a^nb^2n.如果它选择每次消耗两个,我们得到 a^nb^2n。 If it chooses some of both, we get a number of b in between these extremes.如果它选择两者中的一些,我们会在这些极端之间得到一些 b。 We only accept when we exhaust the input with an empty stack.只有当我们用空堆栈耗尽输入时,我们才会接受。

Q    s    S    Q'    S'    Comment

q0   e    e    qA    e     Allow empty string to be accepted

q0   a    x    q0    ax    Count a and push onto stack
q0   e    x    q1    x     Transition to counting b

q1   b    ax   q1    x     Mark off a single b for each a
q1   b    ax   q2    x     Mark off the first of two b for this a
q1   e    e    qA    e     Allow string in language to be accepted

q2   b    x    q1    x     Mark off the second of two b for this a

In this PDA we have q0 as the initial state and qA as the accepting state.在这个 PDA 中,我们将q0作为初始 state,将qA作为接受 state。 Processing on aabbb :aabbb上处理:

   q0, aabbb, e 
-> q0, abbb, a 
-> q0, bbb, aa
-> q1, bbb, aa
-> q1, bb, a
-> q2, b, e
-> q1, e, e
-> qA, e, e

Of course there are many parsings that don't lead to qA but in an NPDA we accept if there is at least one.当然,有许多解析不会导致 qA,但在 NPDA 中,如果至少有一个,我们会接受。

This image include graphical push down automata of this Language此图像包括该语言的图形下推自动机

该语言的 NPDA

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

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