简体   繁体   English

这个语法的 PDA 是什么?

[英]What is the PDA for this grammar?

For the grammar given below obtain the corresponding PDA:对于下面给出的语法,获取相应的 PDA:

S -> aABB | aAA
A -> aBB | a
B -> bBB | A
C -> a

I tried solving it but apparently it was incorrect.我尝试解决它,但显然它是不正确的。 If anyone knows how to solve it help me out.如果有人知道如何解决它,请帮助我。

We could try to write a nice PDA that accepts the language in an efficient and idiomatic manner, or we could just use the algorithm to produce a PDA from the grammar directly.我们可以尝试编写一个漂亮的 PDA,以一种有效和惯用的方式接受该语言,或者我们可以直接使用该算法从语法中生成一个 PDA。 We'll just do the algorithmic way because the other way is hard.我们将只使用算法方式,因为另一种方式很难。

Our PDA can have transitions which first push the start symbol onto the stack, then proceeds to nondeterministically replace the top-of-stack symbol with the RHS of productions and consuming the input, until either all paths dead-end or the input gets exhausted at the same time as the stack empties, in which case we accept.我们的 PDA 可以进行转换,首先将开始符号推入堆栈,然后继续不确定地用产生式的 RHS 替换栈顶符号并消耗输入,直到所有路径都死路或输入在在堆栈清空的同时,我们接受这种情况。 This PDA looks like this:这个 PDA 看起来像这样:

q    s    St    q'    S'        comment
q0   -    Z0    q1    SZ0       put the start nonterminal on the stack
q1   -    Sx    q1    aABBx     production S -> aABB
q1   -    Sx    q1    aAAx      production S -> aAA
q1   -    Ax    q1    aBBx      production A -> aBB
q1   -    Ax    q1    ax        production A -> a
q1   -    Bx    q1    bBBx      production B -> bBB
q1   -    Bx    q1    Ax        production B -> A
q1   -    Cx    q1    ax        production C -> a
q1   a    ax    q1    x         consume terminal symbol a
q1   b    bx    q1    x         consume terminal symbol b
q1   -    Z0    q2    Z0        transition to accepting state

Let's see this PDA in action by tracing execution for the string aaaa along a path that will accept it:让我们通过沿接受它的路径跟踪字符串 aaaa 的执行来查看这个 PDA 的运行情况:

q    input    St                comment
q0   aaaa     Z0                initial configuration
q1   aaaa     SZ0               wrote the start nonterminal to the stack
q1   aaaa     aABBZ0            popped S and replaced with RHS of production
q1   aaa      ABBZ0             popped a, consumed input, did not replace
q1   aaa      aBBZ0             popped A and replaced with RHS of production
q1   aa       BBZ0              popped a, consumed input, did not replace
q1   aa       ABZ0              popped B and replaced with RHS of production
q1   aa       aBZ0              popped A and replaced with RHS of production
q1   a        BZ0               popped a, consumed input, did not replace
q1   a        AZ0               popped B and replaced with RHS of production
q1   a        aZ0               popped A and replaced with RHS of production
q1   -        Z0                popped a, consumed input, did not replace
q2   -        Z0                transitioned to accept state

This construction works generally and, while it doesn't produce the nicest or most straightfoward PDA in many cases, it certainly is not a bad PDA by any means.这种结构通常有效,虽然在许多情况下它不会产生最好或最直接的 PDA,但无论如何它肯定不是一个糟糕的 PDA。

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

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