Closure Properties of ContextFree languages Summer 2004 COMP

  • Slides: 41
Download presentation
Closure Properties of Context-Free languages Summer 2004 COMP 335 1

Closure Properties of Context-Free languages Summer 2004 COMP 335 1

Union Context-free languages are closed under: Union is context free Summer 2004 is context-free

Union Context-free languages are closed under: Union is context free Summer 2004 is context-free COMP 335 2

Example Language Grammar Union Summer 2004 COMP 335 3

Example Language Grammar Union Summer 2004 COMP 335 3

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 Summer 2004 COMP 335 4

Concatenation Context-free languages Concatenation are closed under: is context free Summer 2004 is context-free

Concatenation Context-free languages Concatenation are closed under: is context free Summer 2004 is context-free COMP 335 5

Example Language Grammar Concatenation Summer 2004 COMP 335 6

Example Language Grammar Concatenation Summer 2004 COMP 335 6

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 Summer 2004 COMP 335 7

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

Star Operation Context-free languages Star-operation are closed under: is context free Summer 2004 is context-free COMP 335 8

Example Language Grammar Star Operation Summer 2004 COMP 335 9

Example Language Grammar Star Operation Summer 2004 COMP 335 9

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 Summer 2004 COMP 335 10

Negative Properties of Context-Free Languages Summer 2004 COMP 335 11

Negative Properties of Context-Free Languages Summer 2004 COMP 335 11

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

Intersection Context-free languages intersection are not closed under: is context free Summer 2004 not necessarily context-free COMP 335 12

Example Context-free: Intersection NOT context-free Summer 2004 COMP 335 13

Example Context-free: Intersection NOT context-free Summer 2004 COMP 335 13

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

Complement Context-free languages complement are not closed under: is context free Summer 2004 not necessarily context-free COMP 335 14

Example Context-free: Complement Summer 2004 NOT context-free COMP 335 15

Example Context-free: Complement Summer 2004 NOT context-free COMP 335 15

Intersection of Context-free languages and Regular Languages Summer 2004 COMP 335 16

Intersection of Context-free languages and Regular Languages Summer 2004 COMP 335 16

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 Summer 2004 context-free COMP 335 17

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

Machine NPDA for DFA for regular context-free Construct a new NPDA machine that accepts simulates in parallel Summer 2004 COMP 335 and 18

NPDA DFA transition NPDA transition Summer 2004 COMP 335 19

NPDA DFA transition NPDA transition Summer 2004 COMP 335 19

NPDA DFA transition NPDA transition Summer 2004 COMP 335 20

NPDA DFA transition NPDA transition Summer 2004 COMP 335 20

NPDA DFA initial state NPDA Initial state Summer 2004 COMP 335 21

NPDA DFA initial state NPDA Initial state Summer 2004 COMP 335 21

NPDA DFA final states NPDA final states Summer 2004 COMP 335 22

NPDA DFA final states NPDA final states Summer 2004 COMP 335 22

Example: context-free NPDA Summer 2004 COMP 335 23

Example: context-free NPDA Summer 2004 COMP 335 23

regular DFA Summer 2004 COMP 335 24

regular DFA Summer 2004 COMP 335 24

context-free Automaton for: NPDA Summer 2004 COMP 335 25

context-free Automaton for: NPDA Summer 2004 COMP 335 25

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 Summer 2004 COMP 335 26

Therefore: is NPDA is context-free Summer 2004 COMP 335 27

Therefore: is NPDA is context-free Summer 2004 COMP 335 27

Applications of Regular Closure Summer 2004 COMP 335 28

Applications of Regular Closure Summer 2004 COMP 335 28

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 Regular Closure context free regular Summer 2004 context-free COMP 335 29

An Application of Regular Closure Prove that: is context-free Summer 2004 COMP 335 30

An Application of Regular Closure Prove that: is context-free Summer 2004 COMP 335 30

We know: is context-free Summer 2004 COMP 335 31

We know: is context-free Summer 2004 COMP 335 31

We also know: is regular Summer 2004 COMP 335 32

We also know: is regular Summer 2004 COMP 335 32

context-free regular (regular closure) context-free is context-free Summer 2004 COMP 335 33

context-free regular (regular closure) context-free is context-free Summer 2004 COMP 335 33

Another Application of Regular Closure Prove that: is not context-free Summer 2004 COMP 335

Another Application of Regular Closure Prove that: is not context-free Summer 2004 COMP 335 34

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

is context-free If (regular closure) Then context-free regular context-free Impossible!!! Therefore, Summer 2004 is not context free COMP 335 35

Decidable Properties of Context-Free Languages Summer 2004 COMP 335 36

Decidable Properties of Context-Free Languages Summer 2004 COMP 335 36

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 Summer 2004 COMP 335 37

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 Summer 2004 COMP 335 is useless 38

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 Summer 2004 COMP 335 39

Example: Infinite language Dependency graph Summer 2004 COMP 335 40

Example: Infinite language Dependency graph Summer 2004 COMP 335 40

Summer 2004 COMP 335 41

Summer 2004 COMP 335 41