languages and finite automata - cs.fit.eduryan/cse4083/busch/class12.pdf · is context 2-free....
TRANSCRIPT
1
Deterministic PDAs
Linz 6th, Section 7.3 DPDA’s and Deterministic Context-Free Languages
2
To begin with we require:
A Non Context-Free Language
(We will prove it at the next class)
3
Regular languages
**ba
Context-free languages
nnba
Non Context-free languages
nnn cba
4
Deterministic PDAs
DPDAs
5
DPDAs
Allowed: q1 q2wba →,
q1
q21, wba →
q32, wca →
6
q1
q21, wba →
q32, wba →
Not allowed:
7
Allowed:1q 2q
wb→,
q1
q21, wb→
q32, wc →
Something must be matched from the stack
8
Not allowed:
q1
q21, wb→
q32, wba →
9
DPDA example
a, → a
b, a→ q0 q1 q2 q3
b, a→
, $→ $
}0:{)( = nbaML nn
a, → a
10
}0:{)( = nbaML nnThe language
is deterministic context-free
11
Definition:
A language is deterministic context-free
if some DPDA accepts it
12
Example of Non-DPDA (NPDA)
, $→ $q1
q2
bb
aa
→
→
,
,
, → q0
→
→
bb
aa
,
,
}{)( RwwML =
13
, $→ $q1
q2
bb
aa
→
→
,
,
, → q0
→
→
bb
aa
,
,
Not allowed in DPDAs
14
NPDAs
Have More Power than
DPDAs
15
We will show:
there is a context-free language
which is not deterministic context-free
(accepted by a NPDA)
(not accepted by a DPDA)
L
16
The language is:
}{}{ 2nnnn babaL =
0n
17
}{}{ 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
18
}{}{ 2nnnn babaL =
is not deterministic context-free
Theorem:
The language
(there is no DPDA that accepts ) L
19
Proof: Assume for contradiction that
}{}{ 2nnnn babaL =
is deterministic context free
Therefore:
there is a DPDA that accepts M L
20
DPDA with M
nnba nb
acceptsnnba 2
acceptsnnba
}{}{)( 2nnnn babaML =
21
The language
is not context-free
}{ nnn cba
(we will prove it later)
Fact 1:
Example 8.1, page 217. The proof uses the context-free pumping lemma.
22
The language
is not context-free
}{ nnn cbaL
}){}{( 2nnnn babaL =
Fact 2:
This is what we really need now. And, it can be proved by the pumping in the same manner as {𝑎𝑛𝑏𝑛𝑐𝑛}.
23
We will construct a NPDA that accepts:
}{ nnn cbaL
}){}{( 2nnnn babaL =
Contradiction!
24
We modify M
nc
Modified M
Replace with cb
nnca
}){}{( 2nnnn babaL =
}){}{( 2nnnn cacaL =
25
The NPDA that accepts }{ nnn cbaL
nnba nb
nc
Modified M
Original M
nnca
26
Since is accepted by a NPDA }{ nnn cbaL
it is context-free
Contradiction!
(since is not context-free)}{ nnn cbaL
27
Therefore:
}{}{ 2nnnn babaL =
There is no DPDA that accepts
End of Proof
Not deterministic context free
28
Positive Propertiesof
Context-Free languages
29
Context-free languages
are closed under: Union
1L is context free
2L is context free
21 LL
is context-free
Union
30
Example
|11 baSS →
|| 222 bbSaaSS →
Union
}{1nnbaL =
}{2RwwL =
21 | SSS →}{}{ Rnn wwbaL =
Language Grammar
31
In general:
The grammar of the union
has new start variable
and additional production 21 | SSS →
For context-free languages
with context-free grammars
and start variables
21, LL
21, GG
21, SS
21 LL
S
32
Context-free languages
are closed under: Concatenation
1L is context free
2L is context free
21LL
is context-free
Concatenation
33
Example
|11 baSS →
|| 222 bbSaaSS →
Concatenation
}{1nnbaL =
}{2RwwL =
21SSS →}}{{ Rnn wwbaL =
Language Grammar
34
In general:
The grammar of the concatenation
has new start variable
and additional production 21SSS →
For context-free languages
with context-free grammars
and start variables
21, LL
21, GG
21, SS
21LL
S
35
Context-free languages
are closed under: Star-operation
L is context free *L is context-free
Star Operation
36
|aSbS →}{ nnbaL =
|11 SSS →*}{ nnbaL =
Example
Language Grammar
Star Operation
37
In general:
The grammar of the star operation
has new start variable
and additional production
For context-free language
with context-free grammar
and start variable
L
G
S
*L
1S
|11 SSS →
38
Negative Propertiesof
Context-Free Languages
39
Context-free languages
are not closed under: intersection
1L is context free
2L is context free
21 LL
not necessarily
context-free
Intersection
40
Example
}{1mnn cbaL =
|
|
cCC
aAbA
ACS
→
→
→
Context-free:
}{2mmn cbaL =
|
|
bBcB
aAA
ABS
→
→
→
Context-free:
}{21nnn cbaLL = NOT context-free
Intersection
41
Context-free languages
are not closed under: complement
L is context free L not necessarily
context-free
Complement
42
}{2121nnn cbaLLLL ==
NOT context-free
Example
}{1mnn cbaL =
|
|
cCC
aAbA
ACS
→
→
→
Context-free:
}{2mmn cbaL =
|
|
bBcB
aAA
ABS
→
→
→
Context-free:
Complement
43
Intersectionof
Context-free languagesand
Regular Languages
44
The intersection of
a context-free language and
a regular language
is a context-free language
1L context free
2L regular
21 LL
context-free
45
1Lfor for 2LNPDA
1M
DFA
2M
Construct a new NPDA machine
that accepts
Machine Machine
M
21 LL
context-free regular
M simulates in parallel and 1M 2M
46
1M 2M
1q 2qcba →,
transition
1p 2pa
transition
NPDA DFA
11, pq cba →,
transition
MNPDA
22, pq
47
1M 2M
0q
initial state
0p
initial state
NPDA DFA
Initial state
MNPDA
00, pq
48
1M 2M
1q
final state
1p
final states
NPDA DFA
final states
MNPDA
11, pq
2p
21, pq
49
M simulates in parallel and 1M 2M
M accepts string w if and only if
accepts string and w1M
accepts string w2M
)()()( 21 MLMLML =
50
Therefore: )()( 21 MLML
(since is NPDA) M
is context-free
21 LL is context-free