Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 Positive Properties of Context-Free languages. 2 Context-free languages are closed under: Union is context free is context-free.

Similar presentations


Presentation on theme: "1 Positive Properties of Context-Free languages. 2 Context-free languages are closed under: Union is context free is context-free."— Presentation transcript:

1 1 Positive Properties of Context-Free languages

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

3 3 Union Example: Union grammar:

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

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

6 6 Concatenation Example: Concatenation grammar:

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

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

9 9 Star operation Example: Star grammar:

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

11 11 Negative Properties of Context-Free Languages

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

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

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

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

16 16 Intersection of Context-free languages and Regular Languages

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

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

19 19 transition NPDADFA transition NPDA

20 20 initial state NPDADFA Initial state NPDA

21 21 final state final states NPDADFA final states NPDA

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

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

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

25 25 We know: is context-free

26 26 is regular We also know:

27 27 is regular is context-free

28 28 Another application Prove that: is not context-free

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

30 30 Decidable Properties of Context-Free Languages

31 31 Membership Question: for grammar find if string

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

33 33 Empty Language Question: for grammar find if

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

35 35 Infinite Language Question: for grammar find if is infinite

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

37 37 Example: Dependency graph infinite

38 38


Download ppt "1 Positive Properties of Context-Free languages. 2 Context-free languages are closed under: Union is context free is context-free."

Similar presentations


Ads by Google