International Journal of Engineering Trends and Technology (IJETT) – Volume... 3. A stack (data structure) —

advertisement
International Journal of Engineering Trends and Technology (IJETT) – Volume 4 Issue 5 - May 2013
Stack Variation In Push Down Automata
(PDA)
1. Navin Kumar Chaudhary
(IV/IV) B.Tech, CSE
K L UNIVERSITY,INDIA
2. Rabin Karmacharya
(IV/IV) B.Tech, CSE
K L UNIVERSITY, INDIA
3. Binaya Ghimire
4. Dr.N. Srinivasu
(IV/IV) B.Tech, CSE
Prof. Dept. CSE
K L UNIVERSITY, INDIA K L UNIVERSITY, INDIA
Department of Computer Science and Engineering, KL University, Vaddeswaram, India

Abstract— The fact is clearly known that the compilers design
for the compilation purpose has great use of push down
automata, a part of automata machine. In particular, we show a
procedure to design the parsers or syntax analyzer using the
concept of pushdown automata .And it is very important part of
the compilation. Mainly Pushdown automata have three
components, out of these stack is most important one. The stack
may vary according to the requirement of the input and
automata machine. Stack is a data structure works on the basis
of LIFO (Last In First Out). Where top of the stack increases as
the value is inserted in the stack called PUSH and decreases
when the value is deleted from the stack called Popped. The
communication between stacks is only allowed by applying a
synch. The pushdown machines have special case ‘Visibly
Pushdown Automata’ (VPA) where the stack operations are
driven by the input. Push Down Automata can be described with
a formal grammar and it is more capable than a finite-state
machine but less than Turing machine. Increase in number of
stacks in PDA increases the problem solving capability and
efficiency of PDA.
Keywords: Compiler, Design, Automata, Compilation, Parser,
Syntax-Analyzer, input, stack, data structure, LIFO, Push, Pop
1. INTRODUCTION:
An automata machine designed for CFG (Context Free
Grammar) is the Pushdown Automata (PDA). The language
generated by the CFG is CFL (Context Free Language)
through which the PDA is designed. Mehlhorn was the first to
play with the input-driven pushdown automaton in 1980[1],
where input alphabet split into three classes and the type of the
current symbol determines whether the automaton must push
onto the stack, pop from the stack, or ignore the stack and the
final complexity is O(log^2/log log n).A Pushdown Automata
contains three parts
1. An input tape
2. A finite control
ISSN: 2231-5381
3. A stack (data structure)
Input tape contains the input values which can be moved one
cell at a time to the left. The control unit contains both tape
head and the stack head, and finds itself at any moment in a
particular state. The stack is a sequential data structure. The
input tape is read and the value is inserted in the stack (called
push operation). The value deleted from the stack is called pop.
F
ig. 1 General Concept of Push Down Automata (PDA)
PDA’s are finite automatons with a stack[2] i.e. a data
structure can be used to store arbiter number of symbols
Push down automata can be defined as: A finite state PDA is 7- tuples
M= {Q,∑, , T, q0,z0,F}
Where,
QA finite set of states
∑A finite set of input alphabet
TA finite set of stack alphabet
q0The initial state
z0the initial stack symbol, z0€T
FFinal state
A transition function form
http://www.ijettjournal.org
Page 1535
International Journal of Engineering Trends and Technology (IJETT) – Volume 4 Issue 5 - May 2013
2. DESIGN AND WORKING PRICIPLE OF PUSH DOWN
AUTOMATA (PDA) :
These problems can be solved by PDA by increasing the
number of stacks into it.
Push down Automata can be designed for acceptance of CFL
by considering two aspects[3]:
 Acceptance by Final state: The PDA accepts its inputs
by consuming it and finally it enters in the final state.
 Acceptance by empty stack : IN the reading of input
string from initial configuration for some PDA, the
stack of PDA becomes empty
4. VARIATION OF STACKS (PROPOSED WAY):
2.1 Example Of Push Down Automata
Let M={Q,∑, ∂, T, q0,z0,F)
PDA for language L={an bn}
The number of stacks may vary according to the requirements
of input tape (input alphabets) and the Parser machine[7]. It
can be increased in number of stacks in PDA if needed to solve
complex problems of CFL (Context Free language). Important
variations are:4.1 TWO STACK PDA
Two stack PDA is a stack variation of normal PDA; the
only difference is the number of stacks present in the
where Q={q0,q1,q2}, ∑={a,b}, T={a,b}, F={q2} and
transitions are as follows :
(q0,a,z0)={(q0,a)}
(q0,a,a)={( q0,a)}
(q0,b, a )={(q1, )}
(q1,b,a)={( q1, )}
(q1, ,z0)={(q2, )}
3. PROBLEM IN NORMAL PDA:
Automata machine PDA[6]. The two stacks PDA machine can
be: M= {Q,∑, , T, q0,z0,z1,F)
Where,
QA finite set of states
∑A finite set of input alphabet
TA finite set of stack alphabet
q0The initial state
z0The initial symbol of first stack
z1  The initial symbol of the second stack
FFinal state
Example: Let the problem L={ an bn cn ;n≥0} is not solvable by
normal PDA but can be solved by two stack PDA; In which:Q{q0,q1,q2,q3}
∑{a,b,c}
q0The initial state
z0The initial symbol of first stack
z1  The initial symbol of the second stack
q3  Final State
Transition are as follows:( q0, a, z0,z1)=( q0,a, z1)
( q0, a,a, z1)=( q0,aa, z1)
( q0, b,a , z1)=( q1, a,b)
( q1, b, a,b)=( q1, a,bb)
( q1, c, a,b)=( q2, , )
( q1, c,a,b)=( q2, , )
( q2, c,a,b)=( q2, , )
( q2, ,z0,z1 )=( q3, )
Normal PDA has one stack which controls the parsing of the
input string in input tape and on each input the input tape will
move one cell left[4]. It is highly impossible to solve and
support the all languages of context free grammar with normal
PDA. Such as for the complex context free languages like
L={an bn cn ;n≥1) the normal PDA will not work and hence we
need another option, Which might be complex and more time
taking than PDA.
4.2 MULTI STACK PDA(N-STACK PDA)
In multi stack PDA there might be a number of stacks which is
used to solve the more complex CFLs not solvable by normal
and two stack PDAs[5]. In this variation of PDA the number of
stacks may vary as in the variation of context free languages
and input string. The context free languages such as L= {an bn
cn dn | n≥1} cannot be solved by normal or two stack PDA but
can be solved by multi stack PDA[9]. The Multi stack PDA
2.2 Transition Diagram for above example:-
Fig. 3 Graphical representation of PDA working principle
ISSN: 2231-5381
http://www.ijettjournal.org
Page 1536
International Journal of Engineering Trends and Technology (IJETT) – Volume 4 Issue 5 - May 2013
works same as normal PDA ; but the stack operations will be
increased.
Else
{
Read Top value from Stack;
Decrement Top value by 1;
}
6. PROPOSED ALGORITHM OF TWO STACK PDA
This proposed algorithm for two stack PDA will solve
most of problems of Context Free Language, which are not
solvable by normal PDA:-
Fig.4 general structure of Multi stack PDA.
6.1 ALGORITHM DESCRIPTION:
5. IMPORTANCE OF STACK VARIATION IN PDA
The stack can be varies to solve and support the complex
CFL, CFG in PDA. With increased in the number of
stacks the PDA can be designed for more complex CFLs.
Since the Time Complexity of the stack operations (i.e.
push and pop) is 0(1). Hence if we increase the number of
stacks on a PDA if wont affects more in the efficiency of
the PDA[8]. The push and pop operation can be
performed in one iteration and hence the complexity of the
PDA will not high
5.1 STACK OPERATIONS IN PDA
Out of three components of PDA the stack is one. The
Stack is a sequential Data Structure whose working
principle is LIFO (Last In First Out). Which means the
element inserted first will be deleted at last. The time
complexity of stack Operations is O(1). Two mainly used
stack operations in PDA are:1. Push: Store an arbiter value into the stack.
Algorithm:
Read Value;
If(Is Stack Full)
Overflow.
Else
{
Increment Top value by 1.
Store value into stack.
}
2. Pop: Delete a stack element.
Algorithm:
If(Is Stack Empty)
Underflow;
ISSN: 2231-5381
1. Read input tape
2. Check its type
2.1 If input type=type 1 then push into stack1
2.2 Change state if stack 2 is not empty
2.3 Increment count1 by one
3. If the input is of type2
3.1 change state if it is first iteration of type 2
3.2 push input value into stack2
3.3 increment count by one
4. Else change state
4.1 If it is first iteration of other type
4.2 Check the stacks if stacks are empty then break
the operation
4.3 Else pop(stack1) and pop(stack2)
5. Follow the above steps till input tape is empty.
6. If input tape ended both stacks are empty then accept
input
7. If input tape is empty and count1 equals count2 then
accept input.
8. If above operation fails then reject it.
6.2 ALGORITHM:
While (input1=empty )
{
Read input [i];
If(input[i]==type1)
{
If(stack2!=empty)
Change state;
Push (input[i]) in stack1
Increase count1 by 1;
}
Else if(input[i]==type2)
{
http://www.ijettjournal.org
Page 1537
International Journal of Engineering Trends and Technology (IJETT) – Volume 4 Issue 5 - May 2013
If(Is first iteration)
Change state;
Push (input[i]) in stack2
Increase count2 by 1;
}
Else
{
If(Is first iteration)
Change state
If(stack1=empty ||stack2=empty )
break;
else
{
Pop(stack1);
Pop(stack2);
}
}
}
If(input tap=empty and stack1 =empty and stack2=empty )
Input string accepted.
else if(input tape =empty and count1=count2)
{
Free(stack1);
Free(stack2);
Input string accepted.
}
Else
Input string is rejected.
Stop.
Above algorithm is designed by considering the stack and its
use in PDA. The acceptance and rejection of input is
determined by this algorithm is decided by stacks used in PDA.
Fig.5 Use of Stack in Normal PDA
7.2 Two Stack PDA
Let, A CFL L={anbncn /n>=1}
Cannot be solved by normal PDA but can be solved by Two
Stack PDA and is represented as:-
7. DIAGRAMATICAL REPRESENTATION OF STACK IN
PDA:
The use of Stack in PDA can be shown as:7.1 NORMAL PDA
Let, A CFL L= {anbn /n>=1)
Can be represented as:-
ISSN: 2231-5381
http://www.ijettjournal.org
Page 1538
International Journal of Engineering Trends and Technology (IJETT) – Volume 4 Issue 5 - May 2013
machines. Therefore the 2 stacks PDA and multi-stack
PDA provide the better options for more complex
CFLs/CFGs; with the synchronization among stacks in a
PDA.
9. ACKNOWLEDGEMENTS:
Fig.6 Use of stack In Two Stack PDA
8. CONCLUSION:
References:
The Parse or Syntax Analyzer can be designed by using
PDA (PUSH DOWN AUTOMATA). Input Tape, Finite
Control and Input Stack are the three components of PDA.
In general PDA single contains[2]. The main Operations
of PDA are handled by stack; therefore PDAs are called
finite automation with stack. A normal PDA I.e. a single
stack PDA is applicable to solve most of CFLs (Context
Free Language) but not to all. Hence we need to look for
other alternatives such as Turing Machine. But the
problems Context Free Languages not solved by normal
PDA can be solved by PDA with increase in numbers of
stack in PDA.
The Time complexity of Stack Operations (I.e. Push and
Pop) it won’t affect much on the performance of and
efficiency of the Machine (PDA) if the number of stacks
increased. Such as the two stack PDA can solve many
complex CFLs or CFGs not solved by normal PDA.As
Mentioned above explanation; The CFL L={a nbncn /
n>=1} cannot be solve by normal PDA but can be solved
by Two stack PDA. Hence with the increase in the number
of stacks the most unsolved problems can be solved. So to
support the Languages given by the CFG the PDA can be
designed by considering the number of stacks to be used in
PDA.
In the same way the n-stack PDA also called Multi-stack
PDA can be designed to support and solve more complex
Problems and languages of CFG, which are not solved by
2-stack PDA. Since the time complexity of stack
operations (PUSH and POP) is O(1), and it is easy to
design and implement, the better way for more complex
CFG/CFLs is PDA with N stacks rather than any other
ISSN: 2231-5381
We would like to express our heartfelt gratitude to our guides
Mr K.V.D Kiran and Dr N.Srinivasu who inspired us to work
on this paper. We also thank the anonymous referees for their
careful reading and many useful remarks.
[1]K. Mehlhorn, Pebbling mountain ranges and its application to
DCFL-recognition. ICALP 1980, Lect. Notes Comput. Sci. 85, Springer (1980)
422-435.
[2]K.V.N Sunitha,N Kalyani - Formal Languages and automata theory(Tata
McGraw Hill Education Private Limited)
[3]Pushdown
automaton
–
Wikipedia,
the
(http://en.wikipedia.org/wiki/Pushdown_automaton)
free
encyclopedia
[4]Defination of PDA,A.A.Puntambekar pages 6-1,Formal Languages And
Automata Theory.
[5]MULTI STACK PDA(N-STACK PDA), (www.denison.edu /academics/
.../mathcs/ bn_ja_formaldefinitionofpda.doc)
[6]PDA with two stacks,A.A.Puntambekar pages 6-18,Formal Languages And
Automata Theory.
[7]A.A.Puntambekar .Comiler Design pages 5-8,Technical Publications,
01-Jan-2010
[8]2-Pushdown Automata.(www.sciencedirect.com/
S0019995867903695)
science/article/
pii/
[9] Model-cheking of ordered multi-pushdown automata( arxiv.org/ pdf/
1209.1916)
http://www.ijettjournal.org
Page 1539
Download