Presentation is loading. Please wait.

Presentation is loading. Please wait.

Context-free Languages

Similar presentations


Presentation on theme: "Context-free Languages"— Presentation transcript:

1 Context-free Languages http://cis.k.hosei.ac.jp/~yukita/

2 2 Context-free grammar G 1

3 3 Parse tree for 000#111 in grammar G 1 A A A A B 0 0 0 # 1 1 1

4 4 The English Language   |  |    |  a | the  boy | girl | flower  touches | likes | sees  with

5 5 Definition 2.1

6 6 Context-free Languages

7 7 Context Dependency

8 8 Example 2.2 G 3

9 9 Example 2.3 G 4

10 10 Parse tree for a+aXa a + a X a

11 11 Parse tree for (a+a)Xa ( a + a ) X a

12 12 Ambiguity in grammar G 5

13 13 A parse tree for a+aXa a + a X a

14 14 Another parse tree for a+aXa a + a X a

15 15 Different derivations for the same parse tree a + a X a

16 16 Leftmost Derivation If a string has two different parse trees, we say that the grammar is ambiguous. A derivation of a string is a leftmost derivation if at every step the leftmost remaining variable is the one replaced. Every parse tree has unique leftmost derivation.

17 17 Definition 2.4 Ambiguity

18 18 Definition 2.5 Chomsky normal form

19 19 Theorem 2.6

20 20 Proof of Th. 2.6

21 21 Proof of Th. 2.6

22 22 Example 2.7 G 6

23 23 Example 2.7 Step 2

24 24 Example 2.7 Step 3

25 25 Example 2.7 Step 4

26 26 Pushdown Automata state control aabb input state control aabb input x y z... stack pushdown automaton finite automaton

27 27 Definition 2.8

28 28 Computation

29 29 Theorem 2.12 A language is context free if and only if some pushdown automaton recognizes it. Lemma 2.13 –If a language is context free, then some pushdown automaton recognizes it. Lemma 2.15 –If a pushdown automaton recognizes some language, then it is context free.

30 30 Proof of Lemma 2.13 CFL  Recognized by PDA

31 31 Proof of Lemma 2.13

32 32 State Diagram of P q start q loop q accept   S$ ,$   ,A  w for rule A  w a,a   for terminal a

33 33 Example 2.14 q start q loop q accept ,S  b ,T   a,a   b,b   ,Sb,Sb ,T,T ,a,a ,Ta,Ta ,T,T ,S$,S$ ,$   S  aTb | b T  Ta | 

34 34 Proof of Lemma 2.15 Recognized by PDA  CFL

35 35 Proof of Lemma 2.15

36 36 A pq  A pr A rq stack height input string generated by A pq p q r generated by A pr generated by A rq

37 37 A pq  aA rs b stack height input string generated by A pq p q rs generated by A rs ab

38 38 Claim 2.16 If A pq generates x, then x can bring P from p with empty stack to q with empty stack.

39 39 Proof (continued)

40 40 Proof (continued)

41 41 Proof (continued)

42 42 Claim 2.17 If x can bring P from p with empty stack to q with empty stack, A pq generates x.

43 43 Proof (continued)

44 44 Proof (continued)

45 45 Corollary 2.18 Every regular language is context free. context-free languages regular languages

46 46 Theorem 2.19 [Pumping Lemma]

47 47 Proof T R R u v x y z T R u v T R u R R v x y y z x z

48 48 Proof

49 49 Proof

50 50 Example 2.20 apap bpbp cpcp vy vy v y Case v and y are homogeneous vy Case v or y is heterogeneous or vy vy

51 51 Example 2.21 apap bpbp cpcp vy vy v y Case v and y are homogeneous vy Case v or y is heterogeneous or See if uv 0 xy 0 z=uxz breaks the balance. See if uv 2 xy 2 z breaks the balance. See if uv 2 xy 2 z or uxz destroys the order. vy vy

52 52 Example 2.22 0p0p 0p0p 1p1p 1p1p vxy 0p0p 0p0p 1p1p 1p1p 0p0p 0p0p 1p1p 1p1p See if the first half of uv 2 xy 2 z begins with 0 while the latter half begins with 1. See if the first half of uv 2 xy 2 z ends with 0 while the latter half ends with 1. See if uv 0 xy 0 z=uxz =0 p 1 i 0 j 1 p, where i and j can not both be p.


Download ppt "Context-free Languages"

Similar presentations


Ads by Google