简体   繁体   中英

Pushdown Automata Construction

How to construct a PDA accepting the language:

( {a^ib^kba^i | i>=0,k>0}) 

To get a PDA for this language, I'd recommend writing two PDAs for each of languages in the union separately, then nondeterministically jumping to one or the other PDA.

To get a PDA for a^(2n) | n > 0, we just need to make sure the number of a's is even; this is a regular language so a DFA will suffice (a DFA is just a PDA that doesn't do anything interesting with the stack)

       /---a---\         state    stack    input    state'    stack'
       |       |         q0       Z        a        q1        Z
       V       |         q1       Z        a        q0        Z
----->q0--a-->q1

To get a PDA for the other one we see that the numbers of a's on the front and back must match; we need the stack for this. We can make the PDA push a's it reads until it sees the first c; then we can make it read c, then at least one d, then another c, and finally the same number of a's as we pushed earlier:

state    stack    input    state'    stack'    comment
q0       x        a        q0        ax        push a's until we see a c
q0       x        c        q1        x         read the required c
q1       x        d        q2        x         read the required d
q2       x        d        q2        x         read as many d as needed
q2       x        c        q3        x         read the 2nd required c
q3       ax       a        q3        x         pop a's until we run out of input
q3       Z        q4       Z         Z         accept on empty stack+state

To hook these up you just need to rename the states of the first one to q0' and q1' and then add a new start state q0'' that works like this:

state    stack    input    state'    stack'    comment
q0''     Z        -        q0        Z         guess we're going to the 2nd PDA
q0''     Z        -        q0'       Z         guess we're going to the 1st PDA

As far as your second question goes:

  1. suppose we have a PDA that accepts by final state but not necessarily empty stack; that is, if the PDA runs out of input while in the final state(s), it accepts, otherwise it rejects. We can add a new state, make it the only accepting one, and add empty transitions from all previously accepting states to it. This new state can have empty transitions to itself that only serve to clear the stack without consuming any additional input. This construction shows that if we can accept by final state alone, we can accept by final state and empty stack together.

  2. suppose we have a PDA that accepts by empty stack but not necessarily final state; that is, if the PDA runs out of input at the same time the stack is empty, the PDA accepts. Add a new state and have all states in the PDA transition to it on the empty stack. Make this state accepting and give it no transitions. The PDA will crash unless the input was already exhausted and it can only be reached if the stack was also empty. This construction shows that if we can accept by empty stack alone, we can accept by empty stack and accepting state together.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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