Professional Documents
Culture Documents
This means:
read x from the input;
pop y off the stack;
push z onto the stack NOTE: Any of x,y,z may be ε.
Pushdown automaton (PDA) SOME BOOK:: 6 tuple system A = (Q, Σ, Γ, s, Δ, F)
NOT considering z0
A PDA is defined by seven tuples (Q, Σ, Г, δ, q0, z0, F)
Where,
Q- Finite set of states.
Σ- Finite set of input symbols | alphabets.
Г- Finite set of stack alphabet
q0- Start state of PDA q0 ε Q
z0- Initial stack symbol; z0 ε Г
F- Set of final states; F is subset of Q
δ- Transition function that maps Q × (Σ U {Є}) × Г à Q × Г*
1 2
The output of δ is a finite set of pairs (p, γ), where p is the new state and γ is the string on the stack after transition.
i.e the moves of PDA can be interpreted as;
δ(q, a, z) = {(P1, γ 1) (p2, γ 2) …………….(pm, γ m)} here q, pi ε Q, a ε Σ U Є & z ε Г, γ i ε Г*
There are two types of PDA:
Deterministic Push Down Automata aka DPDA
=> structure above with output function as
Output Function: Q × (Σ U {Є}) × Г à Q × Г*
- Why DPDA can't accept 𝐿? Because D in DPDA stands for Determinism. That is DPDA can not
decide in nondeterministic way where is the middle of input string (for accepting 𝑤𝑤𝑅 it
should find its middle first! check it one time!).
- So Class of languages NPDA can accept is bigger than DPDA.
Graphical notation of PDA
For finite automaton, the δ’ notation was sufficient to represent sequences of instantaneous
description through which a finite automaton moved, since the ID for a finite automaton is just
its state. However, for PDA’s we need a notation that describes changes in the state, the input
and stack. Thus, we adopt the notation of instantaneous description.
Let P = {Q, Σ, Г, δ, q0, z0, F} be a PDA. Then, we define a relation ├, yields as
(p, aw, zα)├ (q, w, βα)
This move reflects the idea that when in state p, by consuming “a” from the input, and
replacing z on the top of stack by β, we can go from state p to state q.
Note that what remains on the input w, and what is below the top of stack, β, do not influence
the action of the PDA.
For the PDA described earlier accepting language of equal a’s and b’s, [see example 1] the
accepting sequence of ID’s for string 1001 can be shown as;
For the PDA described earlier accepting language of equal a’s and b’s, [see
example 1] the accepting sequence of ID’s for string 1001 can be shown as;
(q0, 1001, Є )
├ (q1, 1001, z0)
├ (q1, 001, 1z0)
├ (q1, 01, z0)
├ (q1, 1, 0z0)
├ (q1, Є, z0 )
|- (q2, Є , Є ) Accepted
P = ({q0, q1, q2}, {0, 1}, {0, 1, z0}, δ, q0, z0, {q2}) where δ is defined as;
Example: Design a top-down parser for the expression "x+y*z" for the grammar G
with the following production rules −
P: S → S+X | X, X → X*Y | Y, Y → (S) | id
Solution
If the PDA is (Q, ∑, S, δ, q0, I, F), then the top-down parsing is −
(x+y*z, I) ⊢(x +y*z, SI) ⊢ (x+y*z, S+XI) ⊢(x+y*z, X+XI)
⊢(x+y*z, Y+X I) ⊢(x+y*z, x+XI) ⊢(+y*z, +XI) ⊢ (y*z, XI)
⊢(y*z, X*YI) ⊢(y*z, y*YI) ⊢(*z,*YI) ⊢(z, YI) ⊢(z, zI) ⊢(ε, I)
Design of a Bottom-Up Parser
For bottom-up parsing, a PDA has the following four types of transitions −
•Push the current input symbol into the stack.
•Replace the right-hand side of a production at the top of the stack with its left-
hand side.
•If the top of the stack element matches with the current input symbol, pop it.
•If the input string is fully read and only if the start symbol ‘S’ remains in the stack,
pop it and go to the final state ‘F’.
Example:Design a top-down parser for the expression "x+y*z" for the grammar G
with the following production rules −
P: S → S+X | X, X → X*Y | Y, Y → (S) | id
Solution
If the PDA is (Q, ∑, S, δ, q0, I, F), then the bottom-up parsing is −
(x+y*z, I) ⊢ (+y*z, xI) ⊢ (+y*z, YI) ⊢ (+y*z, XI) ⊢ (+y*z, SI)
⊢(y*z, +SI) ⊢ (*z, y+SI) ⊢ (*z, Y+SI) ⊢ (*z, X+SI) ⊢ (z, *X+SI)
⊢ (ε, z*X+SI) ⊢ (ε, Y*X+SI) ⊢ (ε, X+SI) ⊢ (ε, SI)
Construction of PDA by Final State: To construct a PDA by final state, we follow these
steps:
1.Start with an empty stack and push a special symbol, say Z0, onto the stack.
2.Read the input string from left to right and use the current input symbol and the top
stack symbol to determine the next move.
3.Based on the move, push or pop a symbol from the stack or leave it unchanged.
4.When the entire input has been read, check if the PDA has reached a final state. If it
has, the input string is accepted; otherwise, it is rejected.
Construction of PDA by Empty Stack: To construct a PDA by empty stack, we follow these
steps:
1.Start with an empty stack and push a special symbol, say Z0, onto the stack.
2.Read the input string from left to right and use the current input symbol and the top
stack symbol to determine the next move.
3.Based on the move, push or pop a symbol from the stack or leave it unchanged.
4.If the PDA reaches a state where the input has been completely read and the stack is
empty, the input string is accepted; otherwise, it is rejected.
Conversion of PDA by Final State to PDA accepting by Empty Stack:
To convert a PDA by final state to a PDA accepting by empty stack, we follow these steps:
1.Add a new start state q0 and an epsilon transition from q0 to the original start state q1.
2.For every final state in the original PDA, add epsilon transitions to a new final state qf
and make it the only final state.
3.Replace every transition of the form (q, a, z, q', z') with (q, a, zX, q', z’) & (q', ε, X, qf, ε),
where X is a new symbol not in the original PDA's alphabet.
4.Finally, add a transition from qf to q0 with epsilon on the input and $ on the stack.