Professional Documents
Culture Documents
Context Free Slides Review
Context Free Slides Review
L = {aibj : j = 4i + 2 }
L = {w {a, b, c}* : every a has a matching b and a matching c somewhere in w and no b or c is considered to match more than one a!} "or e#am$%e, L inc%&des aabcbc, aabcbccc, and bccbbba' (&t the strings aabbc, bcbcaaa, and ab are not in L'
L {anbm : n + m = 2 mod)!, n *, m *}
Example
L = {bam*bam2b+bamn : n 2, m*, +, mn ,, and mi mj -or some i, j} . /010. -or L:
. 2"3 -or L:
d! :hat i- we try to -i# it the same way we -i#ed ba%anced $arentheses getting rid o- e#ce$t at the to$!: 6 67 7 ab 7 a7b 7 ba 7 b7a 7 77 (&t this doesn5t work:
8aabb9 8ab9
8a 8ab9 8ba9 b9
6 6 7a 6 7b 7a . 7a .( 7a .(7a 7b ( 7b (. 7b (.7b . .*
;* . region -irst ;* ( region -irst ;* j&st a sing%e . region ;* two regions, an . -o%%owed by a ( ;* we write this instead o- 7a 7a7a
;* this . region can be com$osed o- a sing%e ba%anced set o- a5s and b5s . .*. ;* or it can have arbitrari%y many s&ch ba%anced sets' .* a.b ;* a ba%anced set is a string o- . regions inside a matching a, b $air .* ab ;* or it bottoms o&t to j&st the $air a, b ( (* ( (*( (* b(a
(* ba
Is L Regular?
L = {w {a, b}* : w contains e4&a% n&mbers o- a5s and b5s}
< <17 7 7>" " L<? " id < 7>" < L<? < id 7 L<? 7 id 1+ >* L
6te$ @'
< < <5 <5 17 7 7 75 75 > " " L "5 "5 < ? " id < 7 75 < L"5 < id 7 L "5 7 id 1+ >* L ?!
1rove that conte#t -ree %ang&ages are c%osed &nder di--erence with any reg&%ar %ang&age'
1rove that L = {anbmcndm: n m} is not conte#t -ree &sing the $&m$ing %emma -or conte#t -ree %ang&ages'
2onvert the -o%%owing conte#t -ree grammar to 2homsky /orma% "orm' 6how yo&r ste$s' 6 a.a A b(b A .2Aa (2Ab 2 20. A 0 . A ( A ab
2onstr&ct a 2"3 -or L = {w: w is the binary re$resentation o- a nonBnegative integer m&%ti$%e o- 4 witho&t %eading Ceros}
6how that L 3! is deterministic conte#t -ree by constr&cting a deterministic 10. -or LD' 3 is as -o%%ows: 6 a6b A a6 A 66 A
"rue or #alse$
a'7he set o- reg&%ar %ang&ages over some a%$habet is a s&bset o- the set o- conte#t -ree %ang&ages over the same a%$habet' b' E- a conte#t -ree grammar is not in reg&%ar grammar -orm it cannot generate a reg&%ar %ang&age' c'. 10. acce$ts an in$&t string i- and on%y i- it cons&mes a%% in$&t and %eaves the 10. in a -ina% state' d' 1ractica% $arsers &se nondeterminism to he%$ them -ind the correct $arse -or a given in$&t' e'E- L* and L2 are conte#t -ree %ang&ages, then L** L*L2 L*,!! is conte#t -ree' -' E- a %ang&age is -inite, it cannot have a conte#t -ree %ang&age as a s&bset'
g'3iven the conte#t -ree grammar, 6 6a6b A , the -o%%owing is a va%id %e-tmost derivation -or the string ababab' 6 6a6b 6a6ba6b 6a6ba6ba6b6 a6ba6ba6b6 aba6ba6b6 ababa6b6 ababab6 ababab h' 7he grammar in $art g! is ambig&o&s' i' 7here are conte#t -ree %ang&ages -or which it is not $ossib%e to constr&ct an &nambig&o&s grammar' j' 7he $rogram yacc &ses a to$Bdown $arsing a%gorithm with one symbo% %ookBahead' k' 7he set o- conte#t -ree %ang&ages over a sing%e character a%$habet is $recise%y the set oreg&%ar %ang&ages over that same a%$habet' %' 1&m$ing is the mechanism by which conte#t -ree grammars generate in-inite %ang&ages' m' 7here is an a%gorithm to constr&ct a rightmost derivation -rom a derivation tree and an a%gorithm to constr&ct derivation tree -rom a rightmost derivation'
n' 2onsider the 2"3 given by the -o%%owing r&%es: 6 66 A a6b A b6b A b6a A a6a A ' Es L 3! reg&%arF
o'
$' E- a conte#t -ree %ang&age is inherent%y ambig&o&s, can it be deterministic conte#t -reeF 4' E- a 10. is in a -ina% state and it has an em$ty stack, then it acce$ts the in$&t string' r' . reg&%ar %ang&age can be a s&$erset o- a conte#t -ree %ang&age' s' 7he conte#t -ree $&m$ing theorem is &sed to $rove %ang&ages are conte#t -ree' t' Et is sometimes $ossib%e to in-er the entire 2"3 -or a 2"L -rom j&st the $arse tree o- a sing%e string in that %ang&age' &' .%% -inite %ang&ages are conte#t -ree' v' E- a %ang&age is not 2"L, it is not reg&%ar'
2onsider the -o%%owing 10., >' 3ive a -orma% de-inition o- L >!' 6how that L >! is deterministic conte#t -ree'
b//b a//a
b/a/
a/b/
2onvert the -o%%owing grammar to 2homsky /orma% "orm' 6how yo&r ste$s' . A c.( ( d A cd. A . A (
1rove that L = { w {a, b, c, d}*: Hb w! Hc w! Hd w! , } is not conte#t -ree &sing the conte#t -ree $&m$ing theorem' Io& may additiona%%y &se any re%evant c%os&re $ro$erties'
3iven a 2"3 3, and a reg&%ar e#$ression , create a decision $roced&re -or determining whether there is any string w s&ch that w L 3! and w L !'
2reate a 10. that recogniCes the -o%%owing %ang&age: { #yC: y a* and #, C {b,c}* and AyA = A#A + ACA } Labe% the transitions o- yo&r 10. with n&mbers and &se the %abe%s to identi-y gro&$s o- transitions that make yo&r 10. nondeterministic' E- yo&r 10. is deterministic, say so'