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 can convert PDA to a context-free grammar such that: simulates computations of with leftmost derivations

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

29 29 Deterministic PDAs - DPDAs

30 30 Deterministic PDA: DPDA Allowed transitions: (deterministic choices)

31 31 Allowed transitions: (deterministic choices)

32 32 Not allowed: (non deterministic choices)

33 33 DPDA example

34 34 The language is deterministic context-free Definition: A language is deterministic context-free if there exists some DPDA that accepts it Example:

35 35 Example of Non-DPDA (PDA)

36 36 Not allowed in DPDAs

37 37 PDAs Have More Power than DPDAs

38 38 Deterministic Context-Free Languages (DPDA) Context-Free Languages PDAs Since every DPDA is also a PDA It holds that:

39 39 We will actually show: We will show that there exists a context-free language which is not accepted by any DPDA Deterministic Context-Free Languages (DPDA) Context-Free Languages (PDA)

40 40 The language is: We will show: is context-free is not deterministic context-free

41 41 Language is context-free Context-free grammar for :

42 42 is not deterministic context-free Theorem: The language (there is no DPDA that accepts )

43 43 Proof: Assume for contradiction that is deterministic context free Therefore: there is a DPDA that accepts

44 44 DPDA with accepts

45 45 DPDA with Such a path exists due to determinism

46 46 The language is not context-free (we will prove this at a later class using pumping lemma for context-free languages) Fact 1: Regular languages Context-free languages

47 47 The language is not context-free Fact 2: (we can prove this using pumping lemma for context-free languages)

48 48 We will construct a PDA that accepts: which is a contradiction!

49 49 Modify Replace with DPDA

50 50 A PDA that accepts Connect the final states of with the final states of

51 51 Since is accepted by a PDA it is context-free Contradiction! (since is not context-free)

52 52 Therefore: There is no DPDA that accepts it End of Proof Is not deterministic context free

53 53 Positive Properties of Context-Free languages

54 54 Context-free languages are closed under: Union is context free is context-free Union

55 55 Example Union LanguageGrammar

56 56 In general: The grammar of the union has new start variable and additional production For context-free languages with context-free grammars and start variables

57 57 Context-free languages are closed under: Concatenation is context free is context-free Concatenation

58 58 Example Concatenation LanguageGrammar

59 59 In general: The grammar of the concatenation has new start variable and additional production For context-free languages with context-free grammars and start variables

60 60 Context-free languages are closed under: Star-operation is context freeis context-free Star Operation

61 61 Example Language Grammar Star Operation

62 62 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

63 63 Negative Properties of Context-Free Languages

64 64 Context-free languages are not closed under: intersection is context free not necessarily context-free Intersection

65 65 Example Context-free: NOT context-free Intersection

66 66 Context-free languages are not closed under: complement is context freenot necessarily context-free Complement

67 67 NOT context-free Example Context-free: Complement

68 68 Intersection of Context-free languages and Regular Languages

69 69 The intersection of a context-free language and a regular language is a context-free language context free regular context-free

70 70 for NPDA DFA Construct a new NPDA machine that accepts Machine context-free regular simulates in parallel and

71 71 transition NPDADFA transition NPDA

72 72 transition NPDADFA transition NPDA

73 73 initial state NPDADFA Initial state NPDA

74 74 final state final states NPDADFA final states NPDA

75 75 Example: NPDA context-free

76 76 DFA regular

77 77 Automaton for: NPDA context-free

78 78 simulates in parallel and accepts stringif and only if accepts string and accepts string In General:

79 79 Therefore: is NPDA is context-free

80 80 Applications of Regular Closure

81 81 The intersection of a context-free language and a regular language is a context-free language context free regular context-free Regular Closure

82 82 An Application of Regular Closure Prove that: is context-free

83 83 We know: is context-free

84 84 is regular We also know:

85 85 regularcontext-free is context-free (regular closure)

86 86 Another Application of Regular Closure Prove that: is not context-free

87 87 context-freeregularcontext-free If is context-free Then Impossible!!! Therefore, is not context free (regular closure)

88 88 Decidable Properties of Context-Free Languages

89 89 Membership Question: for context-free grammar find if string Membership Algorithms: Parsers Exhaustive search parser CYK parsing algorithm

90 90 Empty Language Question: for context-free grammar find if Algorithm: 1.Remove useless variables 2.Check if start variable is useless

91 91 Infinite Language Question: for context-free grammar find if is infinite Algorithm: 1. Remove useless variables 2. Remove unit and productions 3. Create dependency graph for variables 4. If there is a loop in the dependency graph then the language is infinite

92 92 Example: Dependency graph Infinite language

93 93


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

Similar presentations


Ads by Google