Formal Languages - PowerPoint PPT Presentation

1 / 69
About This Presentation
Title:

Formal Languages

Description:

Costas Busch - RPI. Formal Languages. PDAs accept CFGs. Slides based on RPI CSCI 2400 ... Costas Busch - RPI. Grammar. leftmost. derivation. PDA computation ... – PowerPoint PPT presentation

Number of Views:24
Avg rating:3.0/5.0
Slides: 70
Provided by: imsUnist
Category:

less

Transcript and Presenter's Notes

Title: Formal Languages


1
Formal Languages PDAs accept CFGs Slides based on
RPI CSCI 2400 Thanks to Petros Drineas
2
Theorem
Context-Free Languages (Grammars)
Languages Accepted by PDAs
3
Proof - Step 1
Context-Free Languages (Grammars)
Languages Accepted by PDAs
Convert any context-free grammar to a PDA
with
4
Proof - Step 2
Context-Free Languages (Grammars)
Languages Accepted by PDAs
Convert any PDA to a context-free
grammar with
5
Converting Context-Free Grammarsto PDAs
Proof - step 1

6
Context-Free Languages (Grammars)
Languages Accepted by PDAs
Convert any context-free grammar to a PDA
with
7
We will convert grammar
to a PDA such that
simulates leftmost derivations of
8
Convert grammar to PDA
Production in
Terminal in
9
PDA computation
Grammar leftmost derivation
Simulates grammar leftmost derivations
Leftmost variable
10
Example
Grammar
PDA
11
Grammar derivation
PDA computation
12
Derivation
Input
Time 0
Stack
13
Derivation
Input
Time 0
Stack
14
Derivation
Input
Time 1
Stack
15
Derivation
Input
Time 2
Stack
16
Derivation
Input
Time 3
Stack
17
Derivation
Input
Time 4
Stack
18
Derivation
Input
Time 5
Stack
19
Derivation
Input
Time 6
Stack
20
Derivation
Input
Time 7
Stack
21
Derivation
Input
Time 8
Stack
22
Derivation
Input
Time 9
Stack
accept
23
In general, it can be shown that
Grammar generates string
If and Only if
PDA accepts
Therefore
24
Therefore
For any context-free language there is a PDA
that accepts
Context-Free Languages (Grammars)
Languages Accepted by PDAs
25
Converting PDAstoContext-Free Grammars
Proof - step 2

26
Context-Free Languages (Grammars)
Languages Accepted by PDAs
Convert any PDA to a context-free
grammar with
27
We will convert PDA to
a context-free grammar such that
simulates computations of with leftmost
derivations
28
Some 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
29
1. Modify the PDA so that the stack is never
empty during computation
Stack
OK
OK
NOT OK
30
Introduce the new symbol to mark the
bottom of the stack
31
At the beginning insert into the stack
Original PDA
new initial state
original initial state
32
Convert all transitions so that after popping
the automaton halts
pop
pop
halting state
33
2. 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
34
3. Modify the PDA so that it has no
transitions popping
35
Example of a PDA in correct form (modifications
are not necessary)
36
Grammar Construction
In grammar
PDA stack symbols
Variables
PDA input symbols
Terminals
Start Variable
Stack bottom symbol
37
PDA transition
Grammar production
38
PDA transition
Grammar production
39
Grammar leftmost derivation
PDA computation
Leftmost variable
40
Example PDA
Grammar
41
Grammar Leftmost derivation
PDA Computation
42
Derivation
Time 0
43
Derivation
Time 1
Stack
44
Derivation
Time 2
Stack
45
Derivation
Time 3
Stack
46
Derivation
Time 4
Stack
47
Derivation
Time 5
empty
Stack
48
However, this grammar conversion does not work
for all PDAs (AA??)
49
Grammar
50
Bad Derivation
Grammar
51
The Correct Grammar Construction
In grammar
PDA stack symbol
Variables
PDA states
Terminals Input symbols of PDA
52
PDA transition
Grammar production
53
PDA transition
Grammar production
m1, not m
For all possible states in
PDA
54
Stack bottom symbol
Start Variable
Start state
accept state
55
Example
Grammar production
56
Example
Grammar productions
57
Example
Grammar production
58
Resulting Grammar
59
(No Transcript)
60
Grammar Leftmost derivation
PDA computation
61
Derivation
Time 0
62
Derivation
Time 1
Stack
63
Derivation
Time 2
Stack
64
Derivation
Time 3
Stack
65
Derivation
Time 4
Stack
66
Derivation
Time 5
empty
Stack
67
In general
If and Only if
Grammar
PDA
68
Thus
Grammar generates
If and Only if
PDA accepts
69
Therefore
For any PDA there is a context-free grammar that
accepts the same language
Context-Free Languages (Grammars)
Languages Accepted by PDAs
Write a Comment
User Comments (0)
About PowerShow.com