In the theory of computation, a branch of theoretical computer science, a pushdown automaton (PDA) is a type of automaton that employs a stack.
Pushdown automata are used in theories about what can be computed by machines. They are more capable than finite-state machines but less capable than Turing machines (see below).Deterministic pushdown automata can recognize all deterministic context-free languages while nondeterministic ones can recognize all context-free languages, with the former often used in parser design.
The term "pushdown" refers to the fact that the stack can be regarded as being "pushed down" like a tray dispenser at a cafeteria, since the operations never work on elements other than the top element. A stack automaton, by contrast, does allow access to and operations on deeper elements. Stack automata can recognize a strictly larger set of languages than pushdown automata.A nested stack automaton allows full access, and also allows stacked values to be entire sub-stacks rather than just single finite symbols.
A finite-state machine just looks at the input signal and the current state: it has no stack to work with, and therefore is unable to access previous values of the input. It can only choose a new state, the result of following the transition. A pushdown automaton (PDA) differs from a finite state machine in two ways:
A pushdown automaton reads a given input string from left to right. In each step, it chooses a transition by indexing a table by input symbol, current state, and the symbol at the top of the stack. A pushdown automaton can also manipulate the stack, as part of performing a transition. The manipulation can be to push a particular symbol to the top of the stack, or to pop off the top of the stack. The automaton can alternatively ignore the stack, and leave it as it is.
Put together: Given an input symbol, current state, and stack symbol, the automaton can follow a transition to another state, and optionally manipulate (push or pop) the stack.
If, in every situation, at most one such transition action is possible, then the automaton is called a deterministic pushdown automaton (DPDA). In general, if several actions are possible, then the automaton is called a general, or nondeterministic, PDA. A given input string may drive a nondeterministic pushdown automaton to one of several configuration sequences; if one of them leads to an accepting configuration after reading the complete input string, the latter is said to belong to the language accepted by the automaton.
We use standard formal language notation:
\Gamma*
\Gamma
\varepsilon
A PDA is formally defined as a 7-tuple:
M=(Q,\Sigma,\Gamma,\delta,q0,Z,F)
Q
\Sigma
\Gamma
\delta
Q x (\Sigma\cup\{\varepsilon\}) x \Gamma x Q x \Gamma*
q0\inQ
Z\in\Gamma
F\subseteqQ
An element
(p,a,A,q,\alpha)\in\delta
M
M
p\inQ
a\in\Sigma\cup\{\varepsilon\}
A\in\Gamma
a
q
A
\alpha\in\Gamma*
(\Sigma\cup\{\varepsilon\})
\delta
Q x (\Sigma\cup\{\varepsilon\}) x \Gamma
Q x \Gamma*
Here
\delta(p,a,A)
p
A
a
\delta(p,a,A)=\{(q,BA)\}
(q,BA)\in\{(q,BA)\},(q,BA)\in\delta(p,a,A),
((p,a,A),\{(q,BA)\})\in\delta
Computations
In order to formalize the semantics of the pushdown automaton a description of the current situation is introduced. Any 3-tuple
(p,w,\beta)\inQ x \Sigma* x \Gamma*
M
\delta
\vdashM
M
(p,a,A,q,\alpha)\in\delta
(p,ax,A\gamma)\vdashM(q,x,\alpha\gamma)
x\in\Sigma*
\gamma\in\Gamma*
In general pushdown automata are nondeterministic meaning that in a given instantaneous description
(p,w,\beta)
Computations of the pushdown automaton are sequences of steps. The computation starts in the initial state
q0
Z
w
(q0,w,Z)
F
\varepsilon
Formally one defines
L(M)=\{w\in\Sigma*|(q0,w,Z)
* | |
\vdash | |
M |
(f,\varepsilon,\gamma)
f\inF
\gamma\in\Gamma*\}
N(M)=\{w\in\Sigma*|(q0,w,Z)
* | |
\vdash | |
M |
(q,\varepsilon,\varepsilon)
q\inQ\}
Here
* | |
\vdash | |
M |
\vdashM
For each single pushdown automaton these two languages need to have no relation: they may be equal but usually this is not the case. A specification of the automaton should also include the intended mode of acceptance. Taken over all pushdown automata both acceptance conditions define the same family of languages.
Theorem. For each pushdown automaton
M
M'
L(M)=N(M')
M
M'
N(M)=L(M')
The following is the formal description of the PDA which recognizes the language
\{0n1n\midn\ge0\}
M=(Q, \Sigma, \Gamma, \delta, q0, Z, F)
Q=\{p,q,r\}
\Sigma=\{0,1\}
\Gamma=\{A,Z\}
q0=p
F=\{r\}
The transition relation
\delta
(p,0,Z,p,AZ)
(p,0,A,p,AA)
(p,\epsilon,Z,q,Z)
(p,\epsilon,A,q,A)
(q,1,A,q,\epsilon)
(q,\epsilon,Z,r,Z)
In words, the first two instructions say that in state any time the symbol is read, one is pushed onto the stack. Pushing symbol on top of another is formalized as replacing top by (and similarly for pushing symbol on top of a).
The third and fourth instructions say that, at any moment the automaton may move from state to state .
The fifth instruction says that in state, for each symbol read, one is popped.
Finally, the sixth instruction says that the machine may move from state to accepting state only when the stack consists of a single .
There seems to be no generally used representation for PDA. Here we have depicted the instruction
(p,a,A,q,\alpha)
a;A/\alpha
\alpha
The following illustrates how the above PDA computes on different input strings. The subscript from the step symbol
\vdash
Every context-free grammar can be transformed into an equivalent nondeterministic pushdown automaton. The derivation process of the grammar is simulated in a leftmost way. Where the grammar rewrites a nonterminal, the PDA takes the topmost nonterminal from its stack and replaces it by the right-hand part of a grammatical rule (expand). Where the grammar generates a terminal symbol, the PDA reads a symbol from input when it is the topmost symbol on the stack (match). In a sense the stack of the PDA contains the unprocessed data of the grammar, corresponding to a pre-order traversal of a derivation tree.
Technically, given a context-free grammar, the PDA has a single state, 1, and its transition relation is constructed as follows.
(1,\varepsilon,A,1,\alpha)
A\to\alpha
(1,a,a,1,\varepsilon)
a
The PDA accepts by empty stack. Its initial stack symbol is the grammar's start symbol.[1]
For a context-free grammar in Greibach normal form, defining (1,γ) ∈ δ(1,a,A) for each grammar rule A → aγ also yields an equivalent nondeterministic pushdown automaton.[2]
The converse, finding a grammar for a given PDA, is not that easy. The trick is to code two states of the PDA into the nonterminals of the grammar.
Theorem. For each pushdown automaton
M
G
f
n
n
f(n)
A finite automaton with access to two stacks is a more powerful device, equivalent in power to a Turing machine.[2] A linear bounded automaton is a device which is more powerful than a pushdown automaton but less so than a Turing machine.
A pushdown automaton is computationally equivalent to a 'restricted' Turing Machine (TM) with two tapes which is restricted in the following manner- On the first tape, the TM can only read the input and move from left to right (it cannot make changes). On the second tape, it can only 'push' and 'pop' data. Or equivalently, it can read, write and move left and right with the restriction that the only action it can perform at each step is to either delete the left-most character in the string (pop) or add an extra character left to the left-most character in the string (push).
That a PDA is weaker than a TM can be brought down to the fact that the procedure 'pop' deletes some data. In order to make a PDA as strong as a TM, we need to save somewhere the data lost through 'pop'. We can achieve this by introducing a second stack. In the TM model of PDA of last paragraph, this is equivalent to a TM with 3 tapes, where the first tape is the read-only input tape, and the 2nd and the 3rd tape are the 'push and pop' (stack) tapes. In order for such a PDA to simulate any given TM, we give the input of the PDA to the first tape, while keeping both the stacks empty. It then goes on to push all the input from the input tape to the first stack. When the entire input is transferred to the 1st stack, now we proceed like a normal TM, where moving right on the tape is the same as popping a symbol from the 1st stack and pushing a (possibly updated) symbol into the second stack, and moving left corresponds to popping a symbol from the 2nd stack and pushing a (possibly updated) symbol into the first stack. We hence have a PDA with 2 stacks that can simulate any TM.
A generalized pushdown automaton (GPDA) is a PDA that writes an entire string of some known length to the stack or removes an entire string from the stack in one step.
A GPDA is formally defined as a 6-tuple:
M=(Q, \Sigma, \Gamma, \delta, q0, F)
Q,\Sigma,\Gamma,q0
\delta
Q x \Sigma\epsilon x \Gamma*\longrightarrowP(Q x \Gamma*)
Computation rules for a GPDA are the same as a PDA except that the
ai+1
bi+1
GPDA's and PDA's are equivalent in that if a language is recognized by a PDA, it is also recognized by a GPDA and vice versa.
One can formulate an analytic proof for the equivalence of GPDA's and PDA's using the following simulation:
Let
\delta(q1,w,x1x2 ⋅ xm)\longrightarrow(q2,y1y2...yn)
where
q1,q2\inQ,w\in\Sigma\epsilon,x1,x2,\ldots,x
* | |
m\in\Gamma |
,m\geq0,y1,y2,\ldots,
* | |
y | |
n\in\Gamma |
,n\geq0
Construct the following transitions for the PDA:
\begin{array}{lcl} \delta'(q1,w,x1)&\longrightarrow&(p1,\epsilon) \\ \delta'(p1,\epsilon,x2)&\longrightarrow&(p2,\epsilon) \\ &\vdots& \\ \delta'(pm-1,\epsilon,xm)&\longrightarrow&(pm,\epsilon) \\ \delta'(pm,\epsilon,\epsilon)&\longrightarrow&(pm+1,yn) \\ \delta'(pm+1,\epsilon,\epsilon)&\longrightarrow&(pm+2,yn-1) \\ &\vdots& \\ \delta'(pm+n-1,\epsilon,\epsilon)&\longrightarrow&(q2,y1). \end{array}
As a generalization of pushdown automata, Ginsburg, Greibach, and Harrison (1967) investigated stack automata, which may additionally step left or right in the input string (surrounded by special endmarker symbols to prevent slipping out), and step up or down in the stack in read-only mode.[4] [5] A stack automaton is called nonerasing if it never pops from the stack. The class of languages accepted by nondeterministic, nonerasing stack automata is NSPACE(n2), which is a superset of the context-sensitive languages.[6] The class of languages accepted by deterministic, nonerasing stack automata is DSPACE(n⋅log(n)).[6]
An alternating pushdown automaton (APDA) is a pushdown automaton with a state set
Q=Q\exists\cupQ\forall
Q\exists\capQ\forall=\emptyset
States in
Q\exists
Q\forall
The model was introduced by Chandra, Kozen and Stockmeyer.[7] Ladner, Lipton and Stockmeyer[8] proved that this model is equivalent to EXPTIME i.e. a language is accepted by some APDA if, and only if, it can be decided by an exponential-time algorithm.
Aizikowitz and Kaminski[9] introduced synchronized alternating pushdown automata (SAPDA) that are equivalent to conjunctive grammars in the same way as nondeterministic PDA are equivalent to context-free grammars.