Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 PDAs Accept Context-Free Languages. 2 Context-Free Languages (Grammars) Languages Accepted by PDAs Theorem:

Similar presentations


Presentation on theme: "1 PDAs Accept Context-Free Languages. 2 Context-Free Languages (Grammars) Languages Accepted by PDAs Theorem:"— Presentation transcript:

1 1 PDAs Accept Context-Free Languages

2 2 Context-Free Languages (Grammars) Languages Accepted by PDAs Theorem:

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

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

5 5 Converting Context-Free Grammars to PDAs Proof - step 1

6 6 Context-Free Languages (Grammars) Languages Accepted by PDAs Convert any context-free grammar to a PDA with:

7 7 to a PDA such that: We will convert grammar simulates leftmost derivations of

8 8 Production in Terminal in Convert grammar to PDA

9 9 Grammar leftmost derivation PDA computation Simulates grammar leftmost derivations Leftmost variable

10 10 Grammar PDA Example

11 11 Grammar derivation PDA computation

12 12 Input Stack Time 0 Derivation:

13 13 Input Stack Time 0 Derivation:

14 14 Input Stack Time 1 Derivation:

15 15 Input Stack Time 2 Derivation:

16 16 Input Stack Time 3 Derivation:

17 17 Input Stack Time 4 Derivation:

18 18 Input Stack Time 5 Derivation:

19 19 Input Stack Time 6 Derivation:

20 20 Input Stack Time 7 Derivation:

21 21 Input Stack Time 8 Derivation:

22 22 Input Stack accept Time 9 Derivation:

23 23 Grammar generates string PDA accepts In general, it can be shown that: If and Only if Therefore

24 24 Therefore: For any context-free language there is a PDA that accepts Context-Free Languages (Grammars) Languages Accepted by PDAs

25 25 Converting PDAs to Context-Free Grammars Proof - step 2

26 26 Context-Free Languages (Grammars) Languages Accepted by PDAs Convert any PDA to a context-free grammar with:

27 27 We will convert PDA to a context-free grammar such that: simulates computations of with leftmost derivations

28 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 29 1. Modify the PDA so that the stack is never empty during computation Stack OK NOT OK

30 30 Introduce the new symbol to mark the bottom of the stack

31 31 Original PDA At the beginning insert into the stack original initial state new initial state

32 32 # # , halting state Convert all transitions so that after popping the automaton halts pop

33 33 PDA , Empty stack 2. Modify the PDA so that at end it empties stack and has a unique accept state , , Old accept states New accept state

34 34 3. Modify the PDA so that it has no transitions popping :

35 35 Example of a PDA in correct form: (modifications are not necessary)

36 36 Grammar Construction In grammar : Terminals: PDA stack symbolsVariables: PDA input symbols Start Variable:Stack bottom symbol

37 37 PDA transition Grammar production

38 38 PDA transition Grammar production

39 39 Grammar leftmost derivation PDA computation Leftmost variable

40 40 Example PDA: Grammar:

41 41 Grammar Leftmost derivation: PDA Computation:

42 42 Derivation: Time 0

43 43 Derivation: Time 1 Stack

44 44 Derivation: Time 2 Stack

45 45 Derivation: Time 3 Stack

46 46 Derivation: Time 4 Stack

47 47 Derivation: Time 5 Stack empty

48 48 However, this grammar conversion does not work for all PDAs:

49 49 Grammar:

50 50 Grammar: Bad Derivation:

51 51 The Correct Grammar Construction In grammar : Terminals: Input symbols of PDA PDA states PDA stack symbol Variables:

52 52 PDA transition Grammar production

53 53 PDA transition Grammar production For all possible states in PDA

54 54 Start Variable: Stack bottom symbol Start state accept state

55 55 Example: Grammar production:

56 56 Example: Grammar productions:

57 57 Example: Grammar production:

58 58 Resulting Grammar:

59 59

60 60 Grammar Leftmost derivation PDA computation

61 61 Derivation: Time 0

62 62 Derivation: Time 1 Stack

63 63 Derivation: Time 2 Stack

64 64 Derivation: Time 3 Stack

65 65 Derivation: Time 4 Stack

66 66 Derivation: Time 5 Stack empty

67 67 In general: If and Only if Grammar PDA

68 68 Thus: If and Only if Grammar generates PDA accepts

69 69 Therefore: For any PDA there is a context-free grammar that accepts the same language Context-Free Languages (Grammars) Languages Accepted by PDAs


Download ppt "1 PDAs Accept Context-Free Languages. 2 Context-Free Languages (Grammars) Languages Accepted by PDAs Theorem:"

Similar presentations


Ads by Google