Title: Formal Languages
1Formal Languages PDAs accept CFGs Slides based on
RPI CSCI 2400 Thanks to Petros Drineas
2Theorem
Context-Free Languages (Grammars)
Languages Accepted by PDAs
3Proof - Step 1
Context-Free Languages (Grammars)
Languages Accepted by PDAs
Convert any context-free grammar to a PDA
with
4Proof - Step 2
Context-Free Languages (Grammars)
Languages Accepted by PDAs
Convert any PDA to a context-free
grammar with
5Converting Context-Free Grammarsto PDAs
Proof - step 1
6Context-Free Languages (Grammars)
Languages Accepted by PDAs
Convert any context-free grammar to a PDA
with
7We will convert grammar
to a PDA such that
simulates leftmost derivations of
8Convert grammar to PDA
Production in
Terminal in
9PDA computation
Grammar leftmost derivation
Simulates grammar leftmost derivations
Leftmost variable
10Example
Grammar
PDA
11Grammar derivation
PDA computation
12Derivation
Input
Time 0
Stack
13Derivation
Input
Time 0
Stack
14Derivation
Input
Time 1
Stack
15Derivation
Input
Time 2
Stack
16Derivation
Input
Time 3
Stack
17Derivation
Input
Time 4
Stack
18Derivation
Input
Time 5
Stack
19Derivation
Input
Time 6
Stack
20Derivation
Input
Time 7
Stack
21Derivation
Input
Time 8
Stack
22Derivation
Input
Time 9
Stack
accept
23In general, it can be shown that
Grammar generates string
If and Only if
PDA accepts
Therefore
24Therefore
For any context-free language there is a PDA
that accepts
Context-Free Languages (Grammars)
Languages Accepted by PDAs
25Converting PDAstoContext-Free Grammars
Proof - step 2
26Context-Free Languages (Grammars)
Languages Accepted by PDAs
Convert any PDA to a context-free
grammar with
27We will convert PDA to
a context-free grammar such that
simulates computations of with leftmost
derivations
28Some Necessary Modifications
If necessary, modify the PDA so that 1. The
stack is never empty during computation 2. It
has a single accept state and empties the
stack when it accepts a string 3. Has
transitions without popping
291. Modify the PDA so that the stack is never
empty during computation
Stack
OK
OK
NOT OK
30Introduce the new symbol to mark the
bottom of the stack
31At the beginning insert into the stack
Original PDA
new initial state
original initial state
32Convert all transitions so that after popping
the automaton halts
pop
pop
halting state
332. Modify the PDA so that at end it empties
stack and has a unique accept state
Empty stack
PDA
New accept state
Old accept states
343. Modify the PDA so that it has no
transitions popping
35Example of a PDA in correct form (modifications
are not necessary)
36Grammar Construction
In grammar
PDA stack symbols
Variables
PDA input symbols
Terminals
Start Variable
Stack bottom symbol
37PDA transition
Grammar production
38PDA transition
Grammar production
39Grammar leftmost derivation
PDA computation
Leftmost variable
40Example PDA
Grammar
41Grammar Leftmost derivation
PDA Computation
42Derivation
Time 0
43Derivation
Time 1
Stack
44Derivation
Time 2
Stack
45Derivation
Time 3
Stack
46Derivation
Time 4
Stack
47Derivation
Time 5
empty
Stack
48However, this grammar conversion does not work
for all PDAs (AA??)
49Grammar
50Bad Derivation
Grammar
51The Correct Grammar Construction
In grammar
PDA stack symbol
Variables
PDA states
Terminals Input symbols of PDA
52PDA transition
Grammar production
53PDA transition
Grammar production
m1, not m
For all possible states in
PDA
54Stack bottom symbol
Start Variable
Start state
accept state
55Example
Grammar production
56Example
Grammar productions
57Example
Grammar production
58Resulting Grammar
59(No Transcript)
60Grammar Leftmost derivation
PDA computation
61Derivation
Time 0
62Derivation
Time 1
Stack
63Derivation
Time 2
Stack
64Derivation
Time 3
Stack
65Derivation
Time 4
Stack
66Derivation
Time 5
empty
Stack
67In general
If and Only if
Grammar
PDA
68Thus
Grammar generates
If and Only if
PDA accepts
69Therefore
For any PDA there is a context-free grammar that
accepts the same language
Context-Free Languages (Grammars)
Languages Accepted by PDAs