“下推自动机”的设计识别语言:a^nb^m | n≤m≤3n
我正在学习自动机考试和正式语言,我必须设计一个能够识别该语言的 PDA:
a^n b^m | n<= m <= 3n
我有一个小小的想法,但我坚持这一点:
首先思考处理所有“a”和每个“a”推“A”
(q0, a, Z)= (q0, AZ)
(q0, a, A)= (q0, AA)
(q0, b, A)= (q1, A)
(q1, b, A)= (q2, A)
(q2, b, A)= (q3, lambda)
(q3, b, A)= (q1, A)
(q3, lambda, A)= (qf, Z)
(q3, lambda, Z)= (qf, Z)
qf = final state, lambda= delete top of stack, Z= initial symbol of the stack
所以我想到了解决方案,但我认为不正确,我做错了什么?
I'm studying for my exam automata and formal languages, I have to design a PDA that recognizes the language:
a^n b^m | n<= m <= 3n
I have a slight idea, but I'm stuck with this:
first thought process all the "a" and each "a" push an "A"
(q0, a, Z)= (q0, AZ)
(q0, a, A)= (q0, AA)
(q0, b, A)= (q1, A)
(q1, b, A)= (q2, A)
(q2, b, A)= (q3, lambda)
(q3, b, A)= (q1, A)
(q3, lambda, A)= (qf, Z)
(q3, lambda, Z)= (qf, Z)
qf = final state, lambda= delete top of stack, Z= initial symbol of the stack
So I thought the solution, but I think is not correct, I'm doing something wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
是的,您的自动机不正确,因为它不接受字符串 ab 或空字符串。您将获得以下机器状态序列:
由于 q1 不接受,因此您的机器无法接受 ab,它采用您所描述的语言。
您的总体思路是正确的:为您看到的每个 a 添加一个 A,然后为您看到的每组 1、2 或 3 个 b 删除一个 A。这个公式显然是不确定的,但我们假设这是可以的,除非需要 DPDA。
这些转换对 A 进行计数并将 A 添加到堆栈中。读完 a 后,我们可以进入下一个状态 q1,并开始计算 b 并弹出 A。
这些转换允许机器不确定地选择是否对特定 A 计数 1、2 或 3 个 b。
这些转换实际上处理计数 1、2 或 3 个 b 并删除 A,返回到 q1 以允许删除额外的A 来自堆栈。
一旦 A 堆栈耗尽,此转换允许 PDA 接受字符串。请注意,如果输入上有任何 b 剩余,PDA 将在 qf 中崩溃,因为那里没有定义任何转换;由于它崩溃了,所以该字符串不被接受(即使堆栈是空的并且它在接受状态下崩溃)。
解决这个问题的另一种方法是为该语言构造一个CFG,然后构造一个自上而下或自下而上的解析器。这种语言的一个简单的 CFG 是:
如果需要 DPDA,那么这是一个更难的问题,并且答案可能是“不存在 DPDA”。说实话,我还没有考虑过为这种语言构建 DPDA。
Yeah, your automaton isn't right since it doesn't accept the string ab, or the empty string for that matter. You get the following sequences of machine states:
Since q1 isn't accepting, your machine fails to accept ab, which is in the language you describe.
You have the right general idea: add an A for each a you see, and then remove an A for each group of 1, 2, or 3 b's you see. This formulation is clearly nondeterministic, but we'll assume that's OK unless a DPDA is asked for.
These transitions count a's and add A's to the stack. When you're done reading a's, we can go to the next state, q1, and start counting b's and popping A's.
These transitions allow the machine to nondeterministically choose whether to count one, two, or three b's for a particular A.
These transitions actually handle counting the one, two or three b's and removing the A, returning to q1 to allow for the removal of additional A's from the stack.
This transition allows the PDA to accept strings once the stack of A's has been exhausted. Note that if there are any b's remaining on the input, the PDA will crash in qf since no transitions are defined there; and since it crashes, the string is not accepted (even though the stack is empty and it crashes in the accepting state).
Another approach to this problem is to construct a CFG for this language, and then construct a top-down or bottom-up parser. An easy CFG for this language is:
If a DPDA is desired, that is a harder problem and one to which the answer may be "no DPDA exists". To be honest, I haven't given the construction of a DPDA for this language any thought.
我知道这有点晚了,但我遇到了同样的问题,我想如果有一个不同的解决方案,所以基本的想法是你将堆栈划分为 3 个分区,其中
最上面的分区 - 第三个分区 - 其目的是确保乙的count 至少等于 a 的计数 -n- ,中间分区 -第二个 - 是为了确保 b 的计数小于或等于 2n ,最后一个分区是为了确保 b 的计数不超过 2n ;所以这是基本思想,当然它是一个 NPDA,这是确切的转换:
现在我们转到 q1 以确保 b 的计数至少等于 a 的计数:
现在我们转到 q2 以确保b 的计数小于或等于 2n :
i know this is a bit late , but i got a cross the same problem and i thought if a different solution , so the basic idea is that you partition your stack into 3 partitions with the following properties
the most upper partition -the third one- its purpose is to make sure that the b's count at least equals the a's count -n- , the middle partition -second one- is to make sure that the b's count is less than or equal to 2n , the last partition is to make sure that the b's count does not exceed 2n ; so this is the basic idea , and of course it is an NPDA , here is the exact transitions :
now we go to q1 to make sure that the b's count at least equals the a's count :
now we go to q2 to make sure that the b's count is less than or equal to 2n :