Deterministic PDAs DPDAs 1 Deterministic PDA DPDA Allowed

  • Slides: 65
Download presentation
Deterministic PDAs - DPDAs 1

Deterministic PDAs - DPDAs 1

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

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

Allowed transitions: (deterministic choices) 3

Allowed transitions: (deterministic choices) 3

Not allowed: (non deterministic choices) 4

Not allowed: (non deterministic choices) 4

DPDA example 5

DPDA example 5

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

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

Example of Non-DPDA (PDA) 7

Example of Non-DPDA (PDA) 7

Not allowed in DPDAs 8

Not allowed in DPDAs 8

PDAs Have More Power than DPDAs 9

PDAs Have More Power than DPDAs 9

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

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

We will actually show: Deterministic Context-Free Languages (DPDA) Context-Free Languages (PDA) We will show

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

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

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

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

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

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

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

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

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

DPDA with accepts 16

DPDA with accepts 16

DPDA with Such a path exists due to determinism 17

DPDA with Such a path exists due to determinism 17

Fact 1: The language is not context-free Context-free languages Regular languages (we will prove

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

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

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

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

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

DPDA Modify Replace with DPDA 21

DPDA Modify Replace with DPDA 21

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

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

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

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

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

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

Positive Properties of Context-Free languages 25

Positive Properties of Context-Free languages 25

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

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

Example Language Grammar Union 27

Example Language Grammar Union 27

In general: For context-free languages with context-free grammars and start variables The grammar of

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

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

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

Example Language Grammar Concatenation 30

Example Language Grammar Concatenation 30

In general: For context-free languages with context-free grammars and start variables The grammar of

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

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

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

Example Language Grammar Star Operation 33

Example Language Grammar Star Operation 33

In general: For context-free language with context-free grammar and start variable The grammar of

In general: For context-free language with context-free grammar and start variable The grammar of the star operation has new start variable and additional production 34

Negative Properties of Context-Free Languages 35

Negative Properties of Context-Free Languages 35

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

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

Example Context-free: Intersection NOT context-free 37

Example Context-free: Intersection NOT context-free 37

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

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

Example Context-free: Complement NOT context-free 39

Example Context-free: Complement NOT context-free 39

Intersection of Context-free languages and Regular Languages 40

Intersection of Context-free languages and Regular Languages 40

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

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

Machine NPDA for DFA for context-free regular Construct a new NPDA machine that accepts

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

NPDA DFA transition NPDA transition 43

NPDA DFA transition NPDA transition 43

NPDA DFA transition NPDA transition 44

NPDA DFA transition NPDA transition 44

NPDA DFA initial state NPDA Initial state 45

NPDA DFA initial state NPDA Initial state 45

NPDA DFA final states NPDA final states 46

NPDA DFA final states NPDA final states 46

Example: context-free NPDA 47

Example: context-free NPDA 47

regular DFA 48

regular DFA 48

context-free Automaton for: NPDA 49

context-free Automaton for: NPDA 49

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

In General: simulates in parallel accepts string and if and only if accepts string and accepts string 50

Therefore: is NPDA is context-free 51

Therefore: is NPDA is context-free 51

Applications of Regular Closure 52

Applications of Regular Closure 52

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

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

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

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

We know: is context-free 55

We know: is context-free 55

We also know: is regular 56

We also know: is regular 56

context-free regular (regular closure) context-free is context-free 57

context-free regular (regular closure) context-free is context-free 57

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

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

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

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

Decidable Properties of Context-Free Languages 60

Decidable Properties of Context-Free Languages 60

Membership Question: for context-free grammar find if string Membership Algorithms: Parsers • Exhaustive search

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

Empty Language Question: for context-free grammar find if Algorithm: 1. Remove useless variables 2.

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

Infinite Language Question: for context-free grammar find if is infinite Algorithm: 1. Remove useless

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 63

Example: Dependency graph Infinite language 64

Example: Dependency graph Infinite language 64

65

65