1 converting npdas to context-free grammars. 2 for any npda we will construct a context-free grammar...
Post on 20-Dec-2015
222 views
TRANSCRIPT
3
Intuition:
G
The grammar simulates the machine
A derivation in Grammar :
abcABCabcS
Current configuration in NPDA M
4
G
in NPDA M
A derivation in Grammar :
abcABCabcS
Input processed Stack contents
terminals variables
5
Some Necessary Modifications
First, we modify the NPDA:• It has a single final state• It empties the stack when it accepts the input
Original NPDA Empty Stack
fq
fq
6
Second, we modify the NPDA transitions:
all transitions will have form
iq jqBa,
or
iq jqCDBa ,
symbolsstack :,, DCB
7
$,0q fq
a, $ 0$a, 0 00a,1
b, $ 1$b, 1 11b, 0
}:{)( ba nnwML
Example of a NPDA in correct form:
symbolstack initial :$
8
The Grammar Construction
)( jiBqq
In grammar
variables have form
G
Terminals are input symbols
states
stacksymbol
10
For each transition
We add production
))(()( klljki DqqCqqaBqq
iq jqCDBa ,
For all states in the NPDA lk qq ,
13
Example:
$,0q fq
a, $ 0$a, 0 00a,1
b, $ 1$b, 1 11b, 0
)$)(1(|)$)(1()$(
)$)(1(|)$)(1()$(
00000
00000000
fffff
ff
qqqqbqqqqbqq
qqqqbqqqqbqq
Grammar productions:
15
)$)(1(|)$)(1()$(
)$)(1(|)$)(1()$(
00000
00000000
fffff
ff
qqqqbqqqqbqq
qqqqbqqqqbqq
)1)(1(|)1)(1()1(
)1)(1(|)1)(1()1(
00000
00000000
fffff
ff
qqqqbqqqqbqq
qqqqbqqqqbqq
)$)(0(|)$)(0()$(
)$)(0(|)$)(0()$(
00000
00000000
fffff
ff
qqqqaqqqqaqq
qqqqaqqqqaqq
Resulting Grammar: ablestart vari:)$( 0 fqq
16
)0)(0(|)0)(0()0(
)0)(0(|)0)(0()0(
00000
00000000
fffff
ff
qqqqaqqqqaqq
qqqqaqqqqaqq
bqq
aqq
)0(
)1(
00
00
)$( 0 fqq
17
Derivation of string abba
)$( 0 fqq )$)(0( 000 fqqqqa
)$( 0 fqqab
)$)(1( 000 fqqqqabb
)$( 0 fqqabba abba
19
Explanation:
By construction of grammar:
wAqq ji
)(
If and only if
in the NPDA going from tothe stack doesn’t change belowand is removed from stack
iq jq
AA
31
We will show:
There is
which is not
a context-free language
deterministic context-free
(accepted by a NPDA)
(not accepted by a DPDA)
L
33
}{}{ 2nnnn babaL
The language is context-freeL
Context-free grammar for : L
21 | SSS
|11 baSS
|22 bbaSS
(there is an NPDA that accepts ) L
34
}{}{ 2nnnn babaL
is not deterministic context-free
Theorem:
The language
(there is no DPDA that accepts ) L
35
Proof:
Assume for contradiction that
}{}{ 2nnnn babaL
is deterministic context free
Therefore:
There exists a DPDAthat accepts
ML
42
is accepted by a NPDA }{ nnn cbaLL
Therefore: L is context-free
Contradiction!
( is not context-free)L