Professional Documents
Culture Documents
Push Down Autometa
Push Down Autometa
Siddharth(2008ecs05)
Ranjan jha(2008ecs10)
1
CFG’s were introduced by Noam Chomsky in
1956.
Oettinger introduced PDA’s for parsing
applications in 1961.
Chomsky, Schutzenberger, and Evey showed
equivalence of CFG’s and PDA’s in 1962.
2
The finite automata(FA) is used only for finite number
of states and when there is bound number of states and
the type of combinations for the states and the input
symbol because finite automata has only limited
memory for processing the strings.
So a more powerful machine is needed which not only
have unbounded values in certain cases but also
remember the symbol read from the input string.
Hence for this purpose we use PDA.
A push-down automaton (PDA) is a seven tuple
(Q, Σ, Γ, δ, q0, z0, F,) where
• Q is a finite set of states.
• Σ is a finite alphabet of tape symbols.
• Γ is a finite alphabet of stack symbols.
• q0 Q is the start state.
• F Q is the set of final states.
• Z0 is start stack symbol.
• δ is the transition relation, i.e., δ is a finite subset of
δ :(Q (Σ ᴧ) Γ*) —›(K Γ*).
Read current symbol and advance head;
6
long factorial(int n){
if (n<=0) return 1;
return n*factorial(n-1);
}
Compute 5!
7
long factorial(int n){
if (n<=0) return 1;
return n*factorial(n-1);
}
f(5)=
5·f(4)
8
long factorial(int n){
if (n<=0) return 1;
return n*factorial(n-1);
}
f(4)= f(5)=
4·f(3) 5·f(4)
9
long factorial(int n){
if (n<=0) return 1;
return n*factorial(n-1);
}
10
long factorial(int n){
if (n<=0) return 1;
return n*factorial(n-1);
}
11
long factorial(int n){
if (n<=0) return 1;
return n*factorial(n-1);
}
12
long factorial(int n){
if (n<=0) return 1;
return n*factorial(n-1);
}
13
long factorial(int n){
if (n<=0) return 1;
return n*factorial(n-1);
}
14
long factorial(int n){
if (n<=0) return 1;
return n*factorial(n-1);
}
15
long factorial(int n){
if (n<=0) return 1;
return n*factorial(n-1);
}
16
long factorial(int n){
if (n<=0) return 1;
return n*factorial(n-1);
}
4·6= f(5)=
24 5·f(4)
17
long factorial(int n){
if (n<=0) return 1;
return n*factorial(n-1);
}
5·24=
120
18
long factorial(int n){
if (n<=0) return 1;
return n*factorial(n-1);
}
Return 5!
= 120
19
By general principles, can carry out any
recursive computation on a stack. Can do it
on a restricted version of an activation record
stack, called a “Pushdown (Stack)
Automaton” or PDA for short.
Q: What is the language generated by
S # | aSa | bSb ?
20
A: Palindromes in {a,b,#}* containing exactly
one #-symbol.
Q: Using a stack, how can we recognize such
strings?
21
A: Use a three phase process:
1. Push mode: Before reading “#”, push everything
on the stack.
2. Reading “#” switches modes.
3. Pop mode: Read remaining symbols making sure
that each new read symbol is identical to symbol
popped from stack.
Accept if able to empty stack completely. Otherwise
reject, and reject if could not pop somewhere.
22
read == peek ?
read a or b ? Pop
Push it Else: CRASH!
(2) empty
(1) read # ? (3) stack?
(ignore stack) ACCEPT
PUSH POP
23
read == peek ?
read a or b ? Pop
Push it Else: CRASH!
(2) empty
(1) read # ? (3) stack?
(ignore stack) ACCEPT
PUSH POP
Input:
aaab#baa
24
read == peek ?
read a or b ? Pop
Push it Else: CRASH!
(2) empty
(1) read # ? (3) stack?
(ignore stack) ACCEPT
PUSH POP
Input:
a
aaab#baa
25
read == peek ?
read a or b ? Pop
Push it Else: CRASH!
(2) empty
(1) read # ? (3) stack?
(ignore stack) ACCEPT
PUSH POP
Input:
a a
aaab#baa
26
read == peek ?
read a or b ? Pop
Push it Else: CRASH!
(2) empty
(1) read # ? (3) stack?
(ignore stack) ACCEPT
PUSH POP
Input:
a a a
aaab#baa
27
read == peek ?
read a or b ? Pop
Push it Else: CRASH!
(2) empty
(1) read # ? (3) stack?
(ignore stack) ACCEPT
PUSH POP
Input:
b a a a
aaab#baa
28
read == peek ?
read a or b ? Pop
Push it Else: CRASH!
(2) empty
(1) read # ? (3) stack?
(ignore stack) ACCEPT
PUSH POP
Input:
b a a a
aaab#baa
29
read == peek ?
read a or b ? Pop
Push it Else: CRASH!
(2) empty
(1) read # ? (3) stack?
(ignore stack) ACCEPT
PUSH POP
Input:
a a a
aaab#baa
30
read == peek ?
read a or b ? Pop
Push it Else: CRASH!
(2) empty
(1) read # ? (3) stack?
(ignore stack) ACCEPT
PUSH POP
Input:
a a
aaab#baa
31
read == peek ?
read a or b ? Pop
Push it Else: CRASH!
(2) empty
(1) read # ? (3) stack?
(ignore stack) ACCEPT
PUSH POP
Input:
a
aaab#baa
REJECT (nonempty stack)
32
read == peek ?
read a or b ? Pop
Push it Else: CRASH!
(2) empty
(1) read # ? (3) stack?
(ignore stack) ACCEPT
PUSH POP
Input:
a a
aaab#baaa
33
read == peek ?
read a or b ? Pop
Push it Else: CRASH!
(2) empty
(1) read # ? (3) stack?
(ignore stack) ACCEPT
PUSH POP
Input:
a
aaab#baaa
34
read == peek ?
read a or b ? Pop
Push it Else: CRASH!
(2) empty
(1) read # ? (3) stack?
(ignore stack) ACCEPT
PUSH POP
Input:
aaab#baaa
Pause input
35
read == peek ?
read a or b ? Pop
Push it Else: CRASH!
(2) empty
(1) read # ? (3) stack?
(ignore stack) ACCEPT
PUSH POP
Input:
aaab#baaa
ACCEPT
36
read == peek ?
read a or b ? Pop
Push it Else: CRASH!
(2) empty
(1) read # ? (3) stack?
(ignore stack) ACCEPT
PUSH POP
Input:
a a
aaab#baaaa
37
read == peek ?
read a or b ? Pop
Push it Else: CRASH!
(2) empty
(1) read # ? (3) stack?
(ignore stack) ACCEPT
PUSH POP
Input:
a
aaab#baaaa
38
read == peek ?
read a or b ? Pop
Push it Else: CRASH!
(2) empty
(1) read # ? (3) stack?
(ignore stack) ACCEPT
PUSH POP
Input:
aaab#baaaa
Pause input
39
read == peek ?
read a or b ? Pop
Push it Else: CRASH!
(2) empty
(1) read # ? (3) stack?
(ignore stack) ACCEPT
PUSH POP
Input:
aaab#baaaa
CRASH
40
To aid analysis, theoretical stack machines restrict the
allowable operations. Each text-book author has his
own version. Sipser’s machines are especially simple:
Push/Pop rolled into a single operation: replace top
stack symbol
No intrinsic way to test for empty stack
Epsilon’s used to increase functionality, result in
default nondeterministic machines.
41
read == peek ?
read a or b ? Pop
Push it Else: CRASH!
(2)
read # ? empty
(1) (ignore stack) (3) stack?
ACCEPT
PUSH POP
Becomes:
aa aa
bb bb
42
x, y z
p q
Meaning of labeling convention:
If at p and next input x and top stack y,
then go to q and replace y by z on stack.
x = : ignore input, don’t read
y = : ignore top of stack and push z
z = : pop y
43
aa aa
bb bb
push $ to
detect
empty
stack
44
aa aa
bb bb
Input:
aaab#baaa
45
aa aa
bb bb
Input:
$
aaab#baaa
46
aa aa
bb bb
Input:
a $
aaab#baaa
47
aa aa
bb bb
Input:
a a $
aaab#baaa
48
aa aa
bb bb
Input:
a a a $
aaab#baaa
49
aa aa
bb bb
Input:
b a a a $
aaab#baaa
50
aa aa
bb bb
Input:
b a a a $
aaab#baaa
51
aa aa
bb bb
Input:
a a a $
aaab#baaa
52
aa aa
bb bb
Input:
a a $
aaab#baaa
53
aa aa
bb bb
Input:
a $
aaab#baaa
54
aa aa
bb bb
Input:
$
aaab#baaa
55
aa aa
bb bb
Input:
aaab#baaa
ACCEPT!
56
57