non-deterministic pushdown automaton
Definition
A non-deterministic pushdown automaton (NPDA), or just pushdown automaton (PDA) is a variation on the idea of a non-deterministic finite automaton (NDFA). Unlike an NDFA, a PDA is associated with a stack (hence the name pushdown). The transition function must also take into account the “state” of the stack.
Formally defined, a pushdown automaton is a 7-tuple , where and , like those in an NDFA, are the set of states, the input alphabet, the start state, and the set of final states respectively. is the stack alphabet, specifying the set of symbols that can be pushed onto the stack. is not necessarily disjoint from . is an element of called the start stack symbol. The transition function is
How It Works
To see how the computing machine works, first imagine with the following features:
-
1.
a finite set of internal states,
-
2.
a horizontal tape of cells each containing an input symbol of ,
-
3.
a tape reader that reads at most one tape cell in any given internal state, and
-
4.
a vertical stack of cells storing symbols of .
Now, given that is in state , with symbol on top of the stack, and tape reader pointing at a tape cell containing symbol , it may do one of the following:
-
•
if , then it
-
(a)
“pops” off the stack,
-
(b)
“pushes” word onto the stack, by starting with symbol , and ending with symbol ,
-
(c)
“consumes” by moving the tape reader to the right of the cell containing , and
-
(d)
enters state ,
provided that ; if , then does nothing.
-
(a)
-
•
if , then, without reading , it
-
(a)
“pops” off the stack,
-
(b)
“pushes” word onto the stack, and
-
(c)
enters state ,
as long as ; if , then does nothing.
-
(a)
If , then gets popped off, and nothing gets pushed onto the stack.
Modes of Acceptance
A PDA is a language acceptor. We describe how words are accepted by a PDA . First, we start with configurations.
A configuration of is an element of . For any word , the configuration is called the start configuration of . A binary relation on the set of configurations is defined as follows: if and are configurations of , then
provided that and , for some , and
-
•
either , and ,
-
•
or , and .
Now, take the reflexive transitive closure of . When , we say that is derivable from . A word is said to be
-
•
accepted on final state by if for some final state ,
-
•
accepted on empty stack by if ,
-
•
accepted on final state and empty stack by if for some .
Languages Accepted by a PDA
Given a mode of acceptance, the set of words accepted by is called the language accepted by based on that mode of acceptance. Given a PDA , there are three languages accepted by , corresponding to the three acceptance modes above.
It turns out that three modes of acceptance are equivalent, in the following sense: if a language is accepted by on one acceptance mode, there are PDA and that accept in the other two acceptance modes.
In general, unless otherwise stated, the language accepted by a PDA stands for the language accepted by on final state.
Remarks.
-
1.
Two PDAs are said to be equivalent if they accept the same language. It can be shown that any PDA is equivalent to a PDA where for all and (called a -free PDA).
-
2.
One of the main reasons for studying PDA is: the notion of a PDA is equivalent to the notion of a context-free grammar. This means that, every language accepted by a PDA is context-free, and every context-free language is accepted by some PDA.
Representation by State Diagrams
Like an NDFA, a PDA can be presented visually as a directed graph, called a state diagram. Instead of simply labelling edges representing transitions with the leading symbol, two additional symbols are added, representing what symbol must be matched and removed from the top of the stack (or if none) and what symbol should be pushed onto the stack (or if none). For instance, the notation
a A/B
for an edge label indicates that a
must be the first symbol in the remaining input string and A
must be the symbol at the top of the stack for this transition to occur, and after the transition, A
is replaced by B
at the top of the stack. If the label had been
, then the symbol at the top of the stack would not matter (the stack could even be empty), and B
would be pushed on top of the stack during the transition. If the label had been , A
would be popped from the stack and nothing would replace it during the transition.
For example, consider the alphabet . Let us define a context-free language that consists of strings where the parentheses are fully balanced. If we define , then a PDA for accepting such strings is: