Positive Properties of ContextFree languages 1 Contextfree languages

  • Slides: 38
Download presentation
Positive Properties of Context-Free languages 1

Positive Properties of Context-Free languages 1

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

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

Union Example: Union grammar: 3

Union Example: Union grammar: 3

In general: Take any two context-free grammars with start variables The union grammar has

In general: Take any two context-free grammars with start variables The union grammar has start variable and is context-free 4

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

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

Concatenation Example: Concatenation grammar: 6

Concatenation Example: Concatenation grammar: 6

In general: Take any two context-free grammars with start variables The concatenation grammar has

In general: Take any two context-free grammars with start variables The concatenation grammar has start variable and is context-free 7

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

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

Star operation Example: Star grammar: 9

Star operation Example: Star grammar: 9

In general: Take any context-free grammars with start variable The concatenation grammar has start

In general: Take any context-free grammars with start variable The concatenation grammar has start variable and is context-free 10

Negative Properties of Context-Free Languages 11

Negative Properties of Context-Free Languages 11

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

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

Counter Example: Context-free: NOT context-free 13

Counter Example: Context-free: NOT context-free 13

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

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

Counter Example: Context-free: NOT context-free 15

Counter Example: Context-free: NOT context-free 15

Intersection of Context-free languages and Regular Languages 16

Intersection of Context-free languages and Regular Languages 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 context-free 17

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 18

NPDA DFA transition NPDA transition 19

NPDA DFA transition NPDA transition 19

NPDA DFA initial state NPDA Initial state 20

NPDA DFA initial state NPDA Initial state 20

NPDA DFA final states NPDA final states 21

NPDA DFA final states NPDA final states 21

simulates in parallel accepts string and if and only if accepts string and accepts

simulates in parallel accepts string and if and only if accepts string and accepts string 22

Therefore: is context-free (since is NPDA) is context-free 23

Therefore: is context-free (since is NPDA) is context-free 23

Example Applications of Regular Closure Prove that: is context-free 24

Example Applications of Regular Closure Prove that: is context-free 24

We know: is context-free 25

We know: is context-free 25

We also know: is regular 26

We also know: is regular 26

is context-free is regular is context-free 27

is context-free is regular is context-free 27

Another application Prove that: is not context-free 28

Another application Prove that: is not context-free 28

is context-free If Then context-free Therefore, regular Is context-free Impossible!!! is not context free

is context-free If Then context-free Therefore, regular Is context-free Impossible!!! is not context free 29

Decidable Properties of Context-Free Languages 30

Decidable Properties of Context-Free Languages 30

Membership Question: for grammar find if string 31

Membership Question: for grammar find if string 31

Membership Question: for grammar find if string Membership Algorithms: Parsers Exhaustive search parser CYK

Membership Question: for grammar find if string Membership Algorithms: Parsers Exhaustive search parser CYK parsing algorithm 32

Empty Language Question: for grammar find if 33

Empty Language Question: for grammar find if 33

Empty Language Question: for grammar find if Algorithm: Remove useless variables Check if start

Empty Language Question: for grammar find if Algorithm: Remove useless variables Check if start variable is useless 34

Infinite Language Question: for grammar find if is infinite 35

Infinite Language Question: for grammar find if is infinite 35

Infinite Language Question: for grammar find if is infinite Algorithm: • Remove useless variables

Infinite Language Question: for grammar find if is infinite Algorithm: • Remove useless variables • Remove unit and lambda productions • Create the dependency graph for variables • If there is a loop in the dependency graph the language is infinite 36

Example: Dependency graph infinite 37

Example: Dependency graph infinite 37

38

38