Presentation is loading. Please wait.

Presentation is loading. Please wait.

PDAs Accept Context-Free Languages

Similar presentations


Presentation on theme: "PDAs Accept Context-Free Languages"— Presentation transcript:

1 PDAs Accept Context-Free Languages
Prof. Busch - LSU

2 Theorem: Context-Free Languages Languages Accepted by (Grammars) PDAs
Prof. Busch - LSU

3 Convert any context-free grammar to a PDA with:
Proof - Step 1: Context-Free Languages (Grammars) Languages Accepted by PDAs Convert any context-free grammar to a PDA with: Prof. Busch - LSU

4 Convert any PDA to a context-free grammar with:
Proof - Step 2: Context-Free Languages (Grammars) Languages Accepted by PDAs Convert any PDA to a context-free grammar with: Prof. Busch - LSU

5 Convert Context-Free Grammars to PDAs
Proof - step 1 Convert Context-Free Grammars to PDAs Prof. Busch - LSU

6 Take an arbitrary context-free grammar
We will convert to a PDA such that: Prof. Busch - LSU

7 Conversion Procedure:
For each For each production in terminal in Add transitions Prof. Busch - LSU

8 Example Grammar PDA Prof. Busch - LSU

9 Example: Input Time 0 Stack Prof. Busch - LSU

10 Derivation: Input Time 1 Stack Prof. Busch - LSU

11 Derivation: Input Time 2 Stack Prof. Busch - LSU

12 Derivation: Input Time 3 Stack Prof. Busch - LSU

13 Derivation: Input Time 4 Stack Prof. Busch - LSU

14 Derivation: Input Time 5 Stack Prof. Busch - LSU

15 Derivation: Input Time 6 Stack Prof. Busch - LSU

16 Derivation: Input Time 7 Stack Prof. Busch - LSU

17 Derivation: Input Time 8 Stack Prof. Busch - LSU

18 Derivation: Input Time 9 Stack Prof. Busch - LSU

19 Derivation: Input Time 10 Stack accept Prof. Busch - LSU

20 Convert PDAs to Context-Free Grammars
Proof - step 2 Convert PDAs to Context-Free Grammars Prof. Busch - LSU

21 Courtesy Costas Busch - RPI
For any NPDA we will construct a context-free grammar with Courtesy Costas Busch - RPI

22 Courtesy Costas Busch - RPI
Intuition: The grammar simulates the machine A derivation in Grammar : terminals variables Input processed Stack contents Current configuration in NPDA Courtesy Costas Busch - RPI

23 Courtesy Costas Busch - RPI
From NPDA to CFG Lets look at how a PDA can consume and empty the stack. We shall define a grammar with variables of the form [pi-1 Yi pi] that would represent going from pi-1 to pi with the net effect of popping Yi. Courtesy Costas Busch - RPI

24 To generate all those strings w that cause P to pop Z0 from its stack while going from q0 to p.

25 Courtesy Costas Busch - RPI

26

27

28

29 Some Necessary Modifications
Modify (if necessary) the NPDA (accepting by reaching final state) so that: 1) The stack is never empty 2) It has a single final state and empties the stack when it accepts a string 3) Has transitions in a special form Courtesy Costas Busch - RPI

30 Courtesy Costas Busch - RPI
Modify the NPDA so that the stack is never empty Stack OK OK NOT OK Courtesy Costas Busch - RPI

31 Courtesy Costas Busch - RPI
Introduce the new symbol to denote the bottom of the stack Courtesy Costas Busch - RPI

32 Courtesy Costas Busch - RPI
At the beginning push into the stack Original NPDA new initial state original initial state Courtesy Costas Busch - RPI

33 Courtesy Costas Busch - RPI
In transitions: replace every instance of with Example: Courtesy Costas Busch - RPI

34 Courtesy Costas Busch - RPI
Convert all transitions so that: if the automaton attempts to pop or replace it will halt Courtesy Costas Busch - RPI

35 Courtesy Costas Busch - RPI
Convert transitions as follows: $ , l halting state Courtesy Costas Busch - RPI

36 Courtesy Costas Busch - RPI
2) Modify the NPDA so that it empties the stack and has a unique final state Empty the stack NPDA l , l , l , Old final states Courtesy Costas Busch - RPI

37 Courtesy Costas Busch - RPI
3) modify the NPDA so that transitions have the following forms: OR Courtesy Costas Busch - RPI

38 Courtesy Costas Busch - RPI
Convert: Courtesy Costas Busch - RPI

39 Courtesy Costas Busch - RPI
Convert: symbols Courtesy Costas Busch - RPI

40 Courtesy Costas Busch - RPI
Convert: symbols Convert recursively Courtesy Costas Busch - RPI

41 Courtesy Costas Busch - RPI
Example of a NPDA in correct form: Courtesy Costas Busch - RPI

42 The Grammar Construction
In grammar : Stack symbol Variables: states Terminals: Input symbols of NPDA Courtesy Costas Busch - RPI

43 Courtesy Costas Busch - RPI
For each transition We add production Courtesy Costas Busch - RPI

44 Courtesy Costas Busch - RPI
For each transition We add productions For all possible states in the automaton Courtesy Costas Busch - RPI

45 Courtesy Costas Busch - RPI
Stack bottom symbol Start Variable: Start state final state Courtesy Costas Busch - RPI

46 Courtesy Costas Busch - RPI
Example: Grammar production: Courtesy Costas Busch - RPI

47 Courtesy Costas Busch - RPI
Example: Grammar productions: Courtesy Costas Busch - RPI

48 Courtesy Costas Busch - RPI
Example: Grammar production: Courtesy Costas Busch - RPI

49 Courtesy Costas Busch - RPI
Resulting Grammar: Courtesy Costas Busch - RPI

50 Courtesy Costas Busch - RPI

51 Courtesy Costas Busch - RPI
Derivation of string Courtesy Costas Busch - RPI

52 Courtesy Costas Busch - RPI
In general: if and only if the NPDA goes from to by reading string and the stack doesn’t change below and then is removed from stack Courtesy Costas Busch - RPI

53 Courtesy Costas Busch - RPI
Therefore: if and only if is accepted by the NPDA Courtesy Costas Busch - RPI

54 Courtesy Costas Busch - RPI
Therefore: For any NPDA there is a context-free grammar that accepts the same language Context-Free Languages (Grammars) Languages Accepted by NPDAs Courtesy Costas Busch - RPI


Download ppt "PDAs Accept Context-Free Languages"

Similar presentations


Ads by Google