Presentation is loading. Please wait.

Presentation is loading. Please wait.

Fall 2004COMP 3351 NPDA’s Accept Context-Free Languages.

Similar presentations


Presentation on theme: "Fall 2004COMP 3351 NPDA’s Accept Context-Free Languages."— Presentation transcript:

1 Fall 2004COMP 3351 NPDA’s Accept Context-Free Languages

2 Fall 2004COMP 3352 Context-Free Languages (Grammars) Languages Accepted by NPDAs Theorem:

3 Fall 2004COMP 3353 Context-Free Languages (Grammars) Languages Accepted by NPDAs Proof - Step 1: Convert any context-free grammar to a NPDA with:

4 Fall 2004COMP 3354 Context-Free Languages (Grammars) Languages Accepted by NPDAs Proof - Step 2: Convert any NPDA to a context-free grammar with:

5 Fall 2004COMP 3355 Converting Context-Free Grammars to NPDAs Proof - step 1

6 Fall 2004COMP 3356 to an NPDA automaton We will convert any context-free grammar Such that: Simulates leftmost derivations of

7 Fall 2004COMP 3357 Input processed Stack contents Input Stack leftmost variable Leftmost derivation Simulation of derivation

8 Fall 2004COMP 3358 Input Stack Leftmost derivation Simulation of derivation string of terminals end of input is reached

9 Fall 2004COMP 3359 An example grammar: What is an equivalent NPDA?

10 Fall 2004COMP 33510 Grammar: NPDA:

11 Fall 2004COMP 33511 Grammar: A leftmost derivation:

12 Fall 2004COMP 33512 Input Stack Time 0 Derivation:

13 Fall 2004COMP 33513 Input Stack Time 0 Derivation:

14 Fall 2004COMP 33514 Input Stack Time 1 Derivation:

15 Fall 2004COMP 33515 Input Stack Time 2 Derivation:

16 Fall 2004COMP 33516 Input Stack Time 3 Derivation:

17 Fall 2004COMP 33517 Input Stack Time 4 Derivation:

18 Fall 2004COMP 33518 Input Stack Time 5 Derivation:

19 Fall 2004COMP 33519 Input Stack Time 6 Derivation:

20 Fall 2004COMP 33520 Input Stack Time 7 Derivation:

21 Fall 2004COMP 33521 Input Stack Time 8 Derivation:

22 Fall 2004COMP 33522 Input Stack accept Time 9 Derivation:

23 Fall 2004COMP 33523 In general: Given any grammar We can construct a NPDA With

24 Fall 2004COMP 33524 Constructing NPDA from grammar : For any production For any terminal

25 Fall 2004COMP 33525 Grammar generates string if and only if NPDA accepts

26 Fall 2004COMP 33526 Therefore: For any context-free language there is a NPDA that accepts the same language Context-Free Languages (Grammars) Languages Accepted by NPDAs

27 Fall 2004COMP 33527 Converting NPDAs to Context-Free Grammars Proof - step 2

28 Fall 2004COMP 33528 For any NPDA we will construct a context-free grammar with

29 Fall 2004COMP 33529 Intuition:The grammar simulates the computation of the machine A derivation in Grammar : Current configuration in NPDA Input processedStack contents terminalsvariables

30 Fall 2004COMP 33530 Some Necessary Modifications Modify (if necessary) the NPDA so that: 1) The stack is never empty 2) has a single final state and empties the stack when it accepts a string 3) Has transitions in a special form:  (q i,a,A)={c 1,c 2,…,c n }, where c i =(q j, ) or c i =(q j,BC)

31 Fall 2004COMP 33531 Example of a NPDA in correct form:

32 Fall 2004COMP 33532 The Grammar Construction In grammar : Terminals: Input symbols of NPDA states Stack symbol Variables:

33 Fall 2004COMP 33533 For each transition We add production

34 Fall 2004COMP 33534 For each transition We add productions For all possible states in the automaton

35 Fall 2004COMP 33535 Start Variable: Stack bottom symbol Start state final state

36 Fall 2004COMP 33536 Example: Grammar production:

37 Fall 2004COMP 33537 Example: Grammar productions:

38 Fall 2004COMP 33538 Example: Grammar production:

39 Fall 2004COMP 33539 Resulting Grammar:

40 Fall 2004COMP 33540

41 Fall 2004COMP 33541 Derivation of string

42 Fall 2004COMP 33542 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

43 Fall 2004COMP 33543 Therefore: if and only if is accepted by the NPDA

44 Fall 2004COMP 33544 Therefore: For any NPDA there is a context-free grammar that accepts the same language Context-Free Languages (Grammars) Languages Accepted by NPDAs

45 Fall 2004COMP 33545 Deterministic PDA DPDA

46 Fall 2004COMP 33546 Deterministic PDA: DPDA Allowed transitions: (deterministic choices)

47 Fall 2004COMP 33547 Allowed transitions: (deterministic choices)

48 Fall 2004COMP 33548 Not allowed: (non deterministic choices)

49 Fall 2004COMP 33549 DPDA example

50 Fall 2004COMP 33550 The language is deterministic context-free

51 Fall 2004COMP 33551 Definition: A language is deterministic context-free if there exists some DPDA that accepts it

52 Fall 2004COMP 33552 Example of Non-DPDA (NPDA)

53 Fall 2004COMP 33553 Not allowed in DPDAs

54 Fall 2004COMP 33554 NPDAs Have More Power than DPDAs

55 Fall 2004COMP 33555 Deterministic Context-Free Languages (DPDA) Context-Free Languages NPDAs Since every DPDA is also a NPDA It holds that:

56 Fall 2004COMP 33556 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 (NPDA)

57 Fall 2004COMP 33557 The language is: We will show: is context-free is not deterministic context-free

58 Fall 2004COMP 33558 Language is context-free Context-free grammar for :

59 Fall 2004COMP 33559 is not deterministic context-free Theorem: The language (there is no DPDA that accepts )

60 Fall 2004COMP 33560 Proof: Assume for contradiction that is deterministic context free Therefore: there is a DPDA that accepts

61 Fall 2004COMP 33561 DPDA with accepts

62 Fall 2004COMP 33562 DPDA with Such a path exists because of the determinism

63 Fall 2004COMP 33563 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

64 Fall 2004COMP 33564 The language is not context-free Fact 2: (we can prove this using pumping lemma for context-free languages)

65 Fall 2004COMP 33565 We will construct a NPDA that accepts: which is a contradiction!

66 Fall 2004COMP 33566 Modify Replace with

67 Fall 2004COMP 33567 The NPDA that accepts Connect final states of with final states of

68 Fall 2004COMP 33568 Since is accepted by a NPDA it is context-free Contradiction! (since is not context-free)

69 Fall 2004COMP 33569 Therefore: There is no DPDA that accepts End of Proof Not deterministic context free


Download ppt "Fall 2004COMP 3351 NPDA’s Accept Context-Free Languages."

Similar presentations


Ads by Google