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q-R }sp !GKP-fʘn&mWDԴF4_dexG=6=eszγ>YMEmWM&28Ȍdɸ%cs'[x֝x֝xr'܉'wɝxr'܉'w2s's޳;4i9m99-iqNsZ89-iqNsZmt.g :ZE,?Q*FۆS~7i-;qdž`L"0RaXG< Ü*S1~HpFٖsxNÈx&FK}a yh#QO'@o)Q T$ IQXDR5^;2 =x xc\F Lyŀ2PBE@63O hİIAAѐ `f0`cp0(2x ӀU*101eBe9y&AeEvDCdu0 '3{j^jY" @1eJ08cЌX.bb,%WXCNA!C#QG!BS? LIjRX?5? TEphꥲy1g(1M6ϻ:b+WyY9("d;N9GLD4=AOk#(   & GdWord Document WordDocument0Word DocumentdWord Document WordDocument0Word DocumentdWord Document WordDocument0Word DocumentdDocument Word.Document.80Documentd Word Document WordDocument0Word Documentd Word Document WordDocument0Word Documentd Word Document WordDocument0Word Documentd Document Word.Document.80.Microsoft Word Documentd Word Document WordDocument0Word Documentd Word Document WordDocument0Word Document/0(  0;[0 0 000$([\{b00 000000000  0=] 0 0 0000 2 3 !A0C0E0G0I0c00000000000000000!%),.:;?]}acdeghijklmnop`DTimesr Sorts>H#>pq>  \DGeneva Sorts>H#>pq>  \ DHelveticaorts>H#>pq>  \0DMonotype SortsH#>pq>  \@DChicago SortsH#>pq>  \PDSymbol SortsH#>pq>  \`DCourier SortsH#>pq>  \pDMather SortsH#>pq>  \ @  @@``   @n?" dd@  @@`` AC: ?@       $ &'()*+,-./012?3456789:;<=> B$Q ̤L}B$2z£[qčEGB$چ=?fz+M B$w\o"`mZB$W]2@*Gu B$]a)ӌ~ bi B$ IQXDR5^,$B$yuK $hweMB$}\0k.6N {s<DB$SқR/K> `1?@{P@ g4dd4upp<4BdBdgH#>8 >kGrammars  DerivationsProduction TypesContext-free Grammars Derivation Trees    Normal Forms for Grammars !Regular Grammars"#$+Pushdown Store Machines,-.Rejection of PDA Diagrams/ 0!1"CF Grammars = PDAs 2#3$4%Deterministic PDAs 5&6'7(8)9*Properties of CF Languages:+;,CF Pumping Lemma<-=.>/?0@1CKY Parsing AlgorithmA2B3C4G5Grammars = Systems of EquationsH6I7J8K9L:/8DEPu0sx,,  y be(,,(d'@W  ` ̙33` ` ff3333f` 333MMM` f` f` 3>?" dd?lKd  d`"   c n?" dd@   @@``PR     c` p>  >   og (  8      T2 @1? ~  N @1?45 ~  N2 @1?oo ~  N @1?z f  61?J:    `:mm1 ?)H6   T Click to edit Master title style! !@   Z$;mm1 ?H    RClick to edit Master text styles Second Level Third Level Fourth Level Fifth Level!     S   Z;wawa1? wT  A*    TD<wawa1? 54  V"22C:135  Part II B  s *%jQ ? 2blueboxc.ppt - Blue Boxes  ZR@(  p  01 ?* *   @  ZtѴwawa1 ? @   RClick to edit Master text styles Second level Third level Fourth level Fifth level!     SB  s *޽h ? a( P 0(   B  s *޽h ? a(d  u 0( DO77Oss   # lδmm1 ?)H6   XB  08c?&]% &,  Ttδwawa1?@5  (Definition 4.1.1: A phrase structure grammar G is a four-tuple, G = (V, S, P, S), where " V  variables or non-terminals and " S  terminals are disjoint,finite, non-empty sets , and " P  the productions, is a finite set of ordered pairs of strings, P ( (V S)* " V " (V S)*) (V S)*, and " S V  the start symbol. An ordered pair <a, b> P that determines a production is always written as a b; we often refer to the components of this pair as the  left-hand and  right-hand sides of the production.B 2<     (5o:H  0%jQ ? d  P    (  ,  T4Nwawa1?  Definition 4.1.2: For grammar G = (V, S, P, S) and x,y (V S)*, x directly derives y, written x y, if x = x1ax2, y = x1bx2, and a b P; also, x derives y, written x * y, if for some ne"0 there exist z0, z1, & , zn (V S)* so that x = z0, y = zn, and zi z i+1 for 0d"i<n. Then the sequences z0, z1, & , zn are referred to as steps of a derivation of length n. If the grammar G is not understood from context we also write its name as a subscript. 2'        "        !   ZP4  # lNmm1 ?)H6   XB  08c?6 6H  0%jQ ? B    ` j (  .  L  TѴwawa1?  Definition 4.1.3: For grammar G = (V, S, P, S) the language defined by G, is L(G) = {x S* | S * x}, and a language for which such a grammar exists is called a phrase structure language. Two grammars G1 and G2 are equivalent if L(G1) = L(G2). 2   B        T4Ҵwawa1?   ZbExample 4.1.1. Consider G where V = {S}, S = {a, b}, and P = {S aSb, S ab}. Then for derivations we have a doubly infinite set of possibilities S aSb aaSbb & ab aabb aaabbb & as there are two permissible rewritings at each point. Hence L(G) = {anbn | ne"1}.`2 2 M  a   tBKM H  0%jQ ? &  M|   $N ( www $ $ TNwawa1? s  jA general production a b is: phrase structure or type 0 if a(VS)+ and b(VS)* context-sensitive or type 1 if a = xAy and b = xwy where AV, and w(VS)+ context-free or type 2 if aV, linear if aV and b S*" V" S*, right-linear if aV and b S*" V, left-linear if aV and b V" S*, terminating if bS*, non-erasing if len(b) e" len(a). 2 2b 27 2                  txU#I $ # lTOmm1 ?)H6   XB $ 08c?6 6H $ 0%jQ ? b0 ((  (R ( TOwawa1? DIf all the productions of a grammar are of one of the types we have indicated, or terminating then the grammar is said to be of that type also. Either a right-linear or a left-linear grammar may also be referred to as a type 3 grammar. A language L is said to be of type T if there exists a grammar G of type T and L = L(G).nE 2  5H ( 0%jQ ?   $ V N ,(  , , TPwawa1? XDefinition 4.1.4: A production a b of grammar G = (V, S, P, S) is called context-free if a V. The grammar G is context-free if all its productions are context-free. 2 L , TtPwawa1?  jTheorem 4.1.1: For context-free grammar G = (V, S, P, S), if w = x1x2 & xk, where ke"1 and xi(V S), 1d"id"k, and w * x, then there exist xi (V S)*, 1d"id"k, so x = x1x2 & xk and xi * xi for i =1, 2, & , k.d 2 %             >   , # lPmm1 ?)H6   XB , 08c?65 6H , 0%jQ ? ` (   0 (  0 0 T4Qwawa1?G ^Definition 4.1.5: Let G = (V, S, P, S) be a context-free grammar. A symbol X (V S) is reachable if S * aXb for some a,b (V S)*; otherwise X is unreachable. A symbol X V is live if X * w for some w S*; otherwise X is dead. A symbol X (V S) is useless if it is either unreachable or dead.0 2.          & 0 TQwawa1?  <Example 4.1.3. Consider the context-free grammar G with variables {S, A, B, C}, start = S, and productions S bb | aB A a | Aa B bB | Ba | AB C ba | aA | Bb | aCb C is unreachable, and B is dead. A is both live and reachable and hence technically not useless, but it contributes nothing to the language defined by G.F 2 b u H 0 0%jQ ? 5 p46(  4 4 TҴwawa1?? (XTheorem 4.1.2: For each context-free grammar G = (V, S, P, S) with L(G) `" , there is G' = (V', S, P', S) so that L(G') = L(G), V' V, P' P, and G' has no dead symbols. 2 *" J 4 TҴwawa1?o Theorem 4.1.3: For each context-free grammar G = (V, S, P, S) with L(G) `" , there is G' = (V', S', P', S) so that L(G') = L(G), S' S, V' V, P' P, and G' has no dead symbols and no unreachable symbols. 2 )!;H 4 0%jQ ? aX 6.8(  8 8 TTӴwawa1?  Example 4.1.6. This example illustrates the elimination of useless symbols using the algorithms from the proofs of Theorems 4.1.2 and 4.1.3. S bb | aB A a | Aa B bB | Ba | AB C ba | aA | Bb | aCb. First V0 = {S, A, C} = V1 = V' so B is dead and all red productions can be removed. Then R0 = {S}, R1 = {S, b} = R2 so a, A, and C are unreachable and all violet productions can be removed.F 2      "     ( H 8 0%jQ ?   Ÿ <G(  < < # lQmm1 ?)H6    < TTRwawa1?g LExample 4.2.1. For the context-free grammar with productions S aSB | e, B bB | e. The derivation S aSB aaSBB aaSBbB has the corresponding derivation treeL 2 2{/b@ 'XB < 08c?6 6 < TA ?1?&  X $ < ZRwawa1?1 9S < ZSwawa1?- 9S < ZtSwawa1?%  9B{H < 0%jQ ? z ]U@(  @ @ TԴwawa1?k NDerivation trees depict: 2 @ TtԴwawa1?Wn U each symbol generated in the derivation the position in which each symbol is placedV 2V @ T4մwawa1?{ ODerivation trees conceal: 2 @ Tմwawa1?VC  d, the relative order of non-nested rewritings- 2-  @ Tմwawa1?gf Q the production used to rewrite each variable the hierarchy of nested rewritingsR 2R @ TTִwawa1? ^(Derivation trees particularly emphasize:) 2)H @ 0%jQ ? © WOD(  D D TSwawa1?.  vExample: productions: S a | aAS A ba | SbA | SS`[ 22>+ D T4Twawa1?F,O 4zleftmost derivation S aAS aSbAS aabAS aabbaS a2b2a2F> 2   P  D TTwawa1?> xrightmost derivation S aAS aAa aSbAa aSbbaa a2b2a2*= 2   P d2 D <1?bId2 D <1?B q d2 D <1?B ! d2 D <1?QRd2  D <1?IR  D ZTwawa1?LN 5S   D ZTUwawa1?h 5a   D ZUwawa1?Nt 5A   D ZVwawa1?Fx 5S  D Zδwawa1?, $  5S  D ZѴwawa1?( N  5b  D Zдwawa1?, n  5A  D ZTдwawa1? $H  5a  D Zwawa1? P  5b  D ZDwawa1? bD  5a XB D@ 01?9XB D 01?XB D 01?EXB D@ 01?66 XB D 01?^: XB D 01?:M> XB D 01?  XB D@ 01? } XB D 01? Y  D Zwawa1? r  5a XB D 01?^>  D Twawa1?  ^(same derivation tree corresponds to both) 2)H D 0%jQ ? < ˕X Hd(  H, H Tִwawa1?7 Theorem 4.2.1: Let G be a context-free grammar, G = (V, S, P, S), A V, and consider a derivation A x1x2 & xk * x, where xi V S (1d"id"k), whose derivation tree is t. Then frontier(t) = x, and each instance of a variable v rewritten in the derivation is the label of the root node of a subtree of t for its sub-derivation, and all other symbols label leaf nodes of t.t| 2 - !      (L H Td7wawa1?  tDefinition 4.2.2: A context-free grammar G is ambiguous if there exists x L(G) with two distinct derivation trees (or equivalently, two distinct leftmost derivations). A language is inherently ambiguous if every grammar is ambiguous.| 2  n H H 0%jQ ?    x L (  Lh L Tdwawa1?tg Example 4.2.2. Ambiguous grammar Productions: S aSB | e, B bB | e. L(G) = e + a+b*Z 2 #   ,1  L TA ?1?v%U X $ L TA ?1?~m X $N L Twawa1? 6  XS aSB aaSBB aaBB aabBB aabB aab- 2lJ L T$wawa1? ^ /  TS aSB aaSBB aaBB aaB aabB aab+ 2lH L 0%jQ ? v x   P (  Pj P TTwawa1? W Example 4.2.3. Unambiguous grammar. Productions: S e | aS | aB, B b | bB. L(G) = e + a+b*` 2 &  >8  P Twawa1?`$ \&Clearly these productions derive L(G).' 2' P Ttwawa1? LTo see that each string in L(G) has only one leftmost derivation consider apbq where p,qe"0. " if p=q=0, then the derivation must be S e, " if p>0 and qe"0, then the derivation must consist of: S aS aaS & ap-1S apB apbB & apbq-1B apbq or S aS aaS & ap-1S ap if q=0' 2K  9>         I{ ` P TԸwawa1?  .Hence the same language, e + a+b*, is described by both ambiguous and unambiguous grammars  ambiguity is a property of the grammar, not the language. 2  =8H P 0%jQ ?   Ş l d T ( %M9" T T # lmm1 ?)H6   XB T 08c?= T Twawa1? Definition 4.3.1: A production a b is referred to as an erasing production if len(b) < len(a). For context-free grammars these productions necessarily take the form A e for some variable A. 2M,Ri T TDwawa1?w .Theorem 4.3.1: If L is a context-free language, then there exists a context-free grammar G with no erasing rules so that L(G) = L-{e}. If L `" and L`" {e}, G may be chosen to have no useless symbols.| 2 y  0 T Twawa1?G  @\The inductively defined sets of variables E1 = {AV | A e P}, and for ie"1, Ei+1 = Ei {A V | A a P and aEi*} effectively provide an algorithm to compute erasing. 2-     7>O8H T 0%jQ ? = /   Xe (  X X T4wawa1?g Example 4.3.1. The grammar with productions S e | SaSbS becomes S SaSbS | aSbS | SabS | SaSb | abS | aSb | Sab | ab.`y 2 !43  X Twawa1?'w "Definition 4.3.2: A production A B is a unit rule if both A and B are variables.`T 2  ! X Twawa1?/ YTheorem 4.3.2: every context-free grammar is equivalent to one with no unit productions.(Z 2 M X TTwawa1?  (Example 4.3.2. The productions A aA | B, B bB | C, C cC | e are first transformed by eliminating A B into A aA | bB| cC | e, B bB | C, C cC | e and then by eliminating B C into A aA | bB | cC | e, B bB | cC | e, C cC | e. 2   )    "  <  -  H X 0%jQ ? 6 \^( pp \& \ Twawa1? Definition 4.3.3: a context-free grammar is in Chomsky normal form provided that each production either has the form A BC with B and C variables, or has the form A l where l is a terminal symbol. Theorem 4.3.3: For each context-free grammar G with e L(G), there is an equivalent grammar in Chomsky normal form.B 2 6/(>,. H \ 0%jQ ? $  0`L(  ` ` # lmm1 ?)H6   XB ` 08c?.% .. ` Tdwawa1?W Definition 4.4.1: A context-free grammar is: " right-linear if all its productions are either right- linear or terminating, " left-linear if all its productions are either left- linear or terminating, " regular if it is either right-linear or left-linear.|  2! G F. ` Twawa1?G $Theorem 4.4.1: If L S* is regular, then there is a right-linear grammar G with L= L(G).T[ 2  C ` T$wawa1?O   >Corollary 4.4.2: no regular language is inherently ambiguous.(? 20H ` 0%jQ ? [H |d(  d d TA ?1?& X $H d 0%jQ ?  <   @h ( X0K h h Twawa1?oc Lemma 4.4.3: For each right-linear grammar G = (V, S, P, S), there is an equivalent right-linear grammar G' = (V', S, P', S) so each non-terminating production A a P' has len(a) d" 2, and each terminating production A x P' has len(x) d" 1. 2 )@/ *,8  h Twawa1?  PExample 4.4.3. According to Lemma 4.4.3, a right-linear grammar such as G = A abA | abB, B aaaB | b is transformed into the equivalent grammar G' = A aX1 | aY1, X1 bA, Y1 bB, B aZ1 | b, Z1 aZ2, Z2 aB. Grammars in this form can then be directly used to define the transitions in an acceptor that mimics their behavior.a 2 B>        |tPK(yH h 0%jQ ? ? z   Plg (  l  l TDwawa1?_ ATheorem 4.4.4: For each right-linear grammar G, L(G) is regular.(B 2 54 l Twawa1? Example 4.4.4. For the grammar of Example 4.4.3, G' = A aX1 | aY1, X1 bA, Y1 bB, B aZ1 | b, Z1 aZ2, Z2 aB the construction in the proof of Theorem 4.4.4 yields the acceptor 2 ,        H>K(E l TA  ?1?~ X  $ l Twawa1? e  zA aY1 abB abb corresponds to the NFA run d(A, abb) d(Y1, bb) d(B, b) {q}.nV 2    >  H l 0%jQ ?   ̙   `6 (    # ldmm1 ?)H6   XB  08c?. .^  Twawa1? Definition 5.1.1: a pushdown acceptor (PDA) M is a 7-tuple, M = (S, S, G, d, s0, Z, R), where S (states), S (input alphabet), and G (stack symbols) are finite non-empty sets, s0S (initial state), ZG (start symbol), R S (recognition states, or final states), and d: S (S {e}) G finite subsets of S G* (transition function).X 2 . / 6  T$wawa1?  *Definition 5.1.2: given a PDA M = (S, S, G, d, s0, Z, R), an instantaneous description (ID) is a triple <s, w, g>S S* G*. 2      Twawa1?'w 6Note that PDAs are non-deterministic and admit e-moves on input (but not stack) from the outset.6b 201 TH  0%jQ ? $X   0L (    Ttwawa1?G ; Definition 5.1.3: for PDA M = (S, S, G, d, s0, Z, R) we define the run-step relation for IDs as follows: ID <s, lw, Xg> directly leads to ID <s', w, ag>, written <s, lw, Xg> | <s', w, ag>, provided lS {e}, XG, and (s', a)d(s, l, X). 2       TԾwawa1?w PbDefinition 5.1.4: for PDA M we define the run relation for IDs I and J, written I | * J, if there exist IDs K0, K1, & , Kn (ne"0) so that I=K0, J=Kn, and Ki | Ki+1 for 0d"i<n.z 2         Pz  T4wawa1?  Definition 5.1.5: for PDA M we define the language recognized by final state as L(M) = {wS* | <s0, w, Z> | * <r, e, g> for some rR and gG*}, and the language recognized by empty stack as Null(M) = {wS* | <s0, w, Z> | * <s, e, e> for some sS}. 2"      #    H  0%jQ ? Ʋ, nf(    Ttwawa1?lS RExample 5.1.1.( 2   TA  ?1?^ .X  $  TԻwawa1? " <s0, aaba, Z> | <s0, aba, XZ> | <s0, ba, XXZ> | <s1, a, XZ> block, " <s0, bb, Z> block, " <s0, aabb, Z> | <s0, abb, XZ> | <s0, bb, XXZ> | <s1, b, XZ> | <s1, e, Z> | <s2, e, e> accepting by both final state and empty stack. 2                                                               6 b  8 {H  0%jQ ?  = p=(  w dx *ht ,t ne   # lmm1 ?)H6   XB  08c?6 6  TA ?1? X $^  TDwawa1?M  But the suggestion of a possible run from state s to state t is misleading as such a run is impossible. Hence the use of PDA diagrams is avoided in our presentation.  Twawa1? Most authors adopt a diagram notation to describe PDAs. Transitions are labeled with the input/stack pair defining a transition, plus the sequence written to the stack. For instance:3H  0%jQ ? ȅd bZ (    Twawa1?g+ RExample 5.1.2.( 2   TA ?1?jmz X $H  0%jQ ? Ʈ 3+(    T4wawa1? FTheorem 5.1.1: Given PDA M1, there is a PDA M2 with L(M1) = Null(M2).G 2          Twawa1??  yTheorem 5.1.2: Given PDA M1, there is a PDA M2 with Null(M1) = L(M2). Furthermore, M2 can be chosen to have a single final state (the only additional state). 2        JH  0%jQ ?  Ex (    # lmm1 ?)H6   XB  08c?& &V  Tdwawa1? Theorem 5.2.1: If L is a context-free language, then there is a PDA M with L = Null(M). Furthermore, M can be chosen to have a single state.( 2   Twawa1?g @Theorem 5.2.2: if L = Null(M) for PDA M, then L is context-free.(A 2 4P  T$wawa1?[  Corollary 5.2.3: every PDA is equivalent to a 1-state PDA using empty stack acceptance, or a 2-state PDA using final state acceptance.( 2zH  0%jQ ?  *"(    Twawa1? ,Example 5.2.4. In this example we seek a context-free grammar for all (and only) the strings over S = {a,b} with an equal number of 'a's and 'b's. Such a grammar is not so easy to formulate directly. So instead we develop a PDA, and then transform it into the desired grammar. Only a single is required and so it need not be shown.DM 2 U,  TTwawa1?OD  Fwhile {(e,Z), (a,B), (b,A)} push e; /* accept (empty stack) if excess=0; or, reduce excess upon mismatch */ while {(a,Z)} push AZ; /* excess 'a' is 1 */ while {(a,A)} push AA; /* increment excess 'a' */ while {(b,Z)} push BZ; /* excess 'b' is 1 */ while {(b,B)} push BB /* increment excess 'b' */Rm 2    K H  0%jQ ? 8Ƅ `(    T"wawa1?G  ^Example 5.2.4. (continued)( 2 >  Tt"wawa1?k  Bwhile {(e,Z), (a,B), (b,A)} push e; /* Z e, B a, A b */ while {(a,Z)} push AZ; /* Z aAZ */ while {(a,A)} push AA; /* A aAA */ while {(b,Z)} push BZ; /* Z bBZ */ while {(b,B)} push BB /* B bBB */ So the complete grammar is Z e | aAZ | bBZ, A b | aAA, B a | bBB. ! 2            #  %  %  $     ^""!(  H  0%jQ ? r  H    (    # l"mm1 ?)H6   XB  08c?&M &  T4#wawa1?wk The intuitive sense of a  deterministic acceptor is that there is exactly one run for each input sequence and the outcome of this run uniquely determines acceptance or rejection. This is imperfectly achieved for the PDA model. 2  T#wawa1?u  .XDefinition 5.3.1: a PDA M = (S, S, G, d, s0, Z, R) is a deterministic PDA (DPDA) provided that (i) for each sS and XG, if d(s, e, X) = , then d(s, l, X) has exactly one element for each lS, (ii) for each sS and XG, if d(s, e, X) `" , then d(s, e, X) has exactly one element and d(s, l, X) = for all lS, and (iii) for sS and aS {e}, if d(s, a, Z) `" , then d(s, a, Z) = {(t, aZ)} for some tS and aG*. 2  %*%    H  0%jQ ? . F( |h#   T#wawa1?G 6Since a PDA halts when its stack is empty and this causes no run for inputs with remaining unread letters, it is forbidden by (iii) for DPDAs to empty their stack. This in turn prohibits the use of empty stack acceptance in DPDAs. The availability of e-moves will subsequently be very helpful so they are retained in DPDAs. But restrictions (i) and (ii) are imposed on DPDAs so that at each step either an e-move or a l-move is possible, but never both. 2: #L  TT$wawa1?/  hDefinition 5.3.2: a language L is deterministic context- free if there exists a DPDA M so that L = L(M).Di 2,H  0%jQ ? fM (  V  T$wawa1? dThe DPDA restrictions on e-moves prove inadequate to insure exactly one run for each input sequence. The difficulty occurs when there is an unending cycle of e-moves. This can result in either of the outcomes: " there is no run if the DPDA encounters the infinite cycle before reading its entire input, or " there are infinitely many runs if the infinite cycle is encountered after the entire input has been readR 2H  0%jQ ? X΁ ( 0)l06 d  T%wawa1? Example 5.3.3. Consider L = {ambnaam | m,ne"1} {ambnabn | m,ne"1}. The use of e-moves is essential in a DPDA since information necessary for some cases must be retained on the stack (the 'b' count), but must be later purged from the stack in other cases. The DPDA below uses its states to check the input belonging to a+ b+ a (a+ + b+) and its stack to check for appropriate counts. 2            2, K  TA ?1? X $H  0%jQ ? ΋ 2*(  C  Tt%wawa1?{ {Lemma 5.3.2: For each DPDA A, there is a DPDA B so that (i) L(A) = L(B), (ii) B scans each input sequence in its entirety.(| 2 q?  T%wawa1? wTheorem 5.3.3: The complement of each deterministic context-free language L is a deterministic context- free language.(x 2 kH  0%jQ ? e Δ (    # l4&mm1 ?)H6   XB  08c? i  T&wawa1? Theorem 6.1.1: the context-free languages are closed under the operations of union, concatenation, and Kleene closure (star).( 2 sgz  T&wawa1?7 zTheorem 6.1.2: if L is context-free and R is regular, then L R is context-free; likewise, if L is deterministic context-free and R is regular, then L R is deterministic context-free.` 2 1\":  TT'wawa1?k  rCorollary 6.1.3: each language which differs from a context-free language by a regular language is context-free.(s 2dH  0%jQ ?  [S(  W  T'wawa1? mTheorem 6.1.4: the context-free languages are closed under substitution, and hence also under homomorphism.(n 2 a^T  T(wawa1? "Theorem 6.1.5: if L S* is a context-free language and M = (SM, S, D, dM, r, s0), is a DGSM, then M(L) = {r(s0, x)| xL} D* is context-free. 2  '     H  0%jQ ? J 0 r(    # lt(mm1 ?)H6   XB  08c?.ue .  T(wawa1?'K Theorem 6.2.1: Let L S* be context-free. Then there exists an integer ne"1 so that for each zL with len(z) e" n, there exist u,v,w,x,yS* so that (i) z = uvwxy, (ii) len(vx) e" 1, (iii) len(vwx) d" n, and (iv) u vk w xk yL for all k e" 0. 2  F) J  f1 H  0%jQ ? 4ڤ 33 >>F3(  ^2  68c? ^2  68c?^ ^2  61?"I^2  68c?& ^2  61?* ^2  61?A"^2  68c? .^2  61? y *^2  68c?  Z4)wawa1? a  9w  Z)wawa1?  Y  5x  Z)wawa1? D Y  5y  ZT*wawa1? i  5u  Z*wawa1? ra  5v  c B C1DEF1?%% 0@PXXhxxxxxxxxxxx(x8pH``Pp8x(  0KL@ ?   c BC)DEF1?"" 8(H X(h0x(88@PXhh(8HXp(EH@ 7    c BCaDE(F01?JJ 8HXphP@@H8((0@PXX`hpxxpX@888 000@ H`ph `8`H`X`h`xXHHXPPX``H 00 8HP`@/   c BC9DEF1?@@((P@pHXxX`h`xp  @PXhhPx@@` 0 @8`Pphppp```p 08xPp`xxxx 08@  ^B  61?iiR^B  61?iizXB @ 01?XB  01?]]XB  01?) XB @ 01?"XB  01?Jee XB  01?Q *  Z+wawa1? 5S   Zt+wawa1?>4 5B   Z+wawa1?D 5B   Z4,wawa1? ~ < 5B   Z,wawa1?< 5C  ! Z,wawa1? 5C  " ZT-wawa1?  5C  # Z-wawa1?\   5A  $ Z4 wawa1? <  5A  % c ZBCqDEdFl1?p h0X@HP@`8p(pP80 (0 @P`p34@F & c bBqCDEhFp1?hhh(p8hHXPX`PpPH@HH@((( (8HXhx58@Or ' c JBCDE\Fd1? 8@Xh`P@P80  (8@P`p/0@'r ( c JBCaDE\Fd1?0H(H8PHh`xh (HXX`/0@Z ) c 2ByCaDEPFX1? 0H8h8x0 @xhPX`PP0`8pPh`),@m 'j * c BBC9DEXF`1?0@ @0`Phxx 8P`p(8-0@ N  + c jB1C!DElFt1?0 (088@HPpPXpxp`PH0   78@] , c bBCDEhFp1?(8P`phXHH@Pp8xH`phXx@(58@B - c BCDEDFL1? 0 H8hHpXxp#$@>%  OJ . c "BCDEHFP1? 8`(0@Xh (0Hh%(@}   / Z wawa1?n  71   0 Z wawa1?0| 71   1 ZT!wawa1?(< 72   2 Z!wawa1?<( 72   3 Z"wawa1?  7q   4 Zt"wawa1?8$  7r   5 Z"wawa1?l|  <e"m+2  6 Z4#wawa1?<,  <d"m+2 XB 7 01?Z--rXB 8 01? == XB 9 01?VA 1VXB : 01?  JXB ; 01?  XB < 01?! XB = 01? !   XB > 01? A B  s *%jQ ?  RJ0( C re   T#wawa1? Example 6.2.1. The language L1 = {akbkck | k e" 0} over alphabet {a, b, c} is not context-free._ 2     6"7  T#wawa1? ZExample 6.2.2. The language L2 = {apbqcpdq | p,q e" 0} over alphabet {a, b, c, d} is not context-free. Note however, that the language {apbqcqdp | p,q e" 0} IS context-free.V 2      ^     ,"^H  0%jQ ? T@, @|(    TT$wawa1?? u1Example 6.2.3: non CF intersection and complement(2 2 %h  T$wawa1?w The languages {apbpcq| p,q e" 0} and {apbqcq| p,q e" 0} are both context-free. In fact, they are deterministic context-free. But {apbpcq| p,q e" 0} {apbqcq| p,q e" 0} = L1 from Example 6.2.1 which is not context-free. 2      X        /PW?d  <1?4  T%wawa1? Also, {apbpcq| p,q e" 0} {apbqcq| p,q e" 0} = ({apbpcq| p,q e" 0} {apbqcq| p,q e" 0}) = L3 by DeMorgan's laws. But {apbqcq| p,q e" 0} and {apbqcq| p,q e" 0} are both context-free (complements of deterministic context-free languages). So L3 = {apbpcq| p,q e" 0} {apbqcq| p,q e" 0} is an example of a context-free language:"S 2                     ]        6  c6G  Tt%wawa1?l{   whose complement is not context-free that is not deterministic context-free is the union of two deterministic context-free languages 2H  0%jQ ?  Z| &  P (  ~   T%wawa1?  @Example 6.2.4. Consider the language L4 = {apbqcrds | either s=0 or p=q=r}. In this language, the pumping lemma does not imply any contradictions  for long strings of the form apbqcr (i.e., s= 0), there are three substrings in which pumping yields only strings in L4; also, for long strings of the form apbqcrds, s>0, there is one substring, ds, where pumping yields only strings in L4. However, if L4 is context-free, then L4 a* b* c* d = {apbpcpd | p e" 0} is also context-free by Theorem 6.1.2. But this is an immediate contradiction to L1 of Example 6.2.1 (i.e., apply the homomorphism h(a) = a, h(b) = b, h(c) = c, h(d) = e to L4 a* b* c* d to get L1). 2      C;   U &      )         _ V      , P  e IH  0%jQ ?