Midterm #2 — Review problems CS 350 — Fall 2018 gilray.org/classes/fall2018/cs350/
Midterm #2 The second midterm is Tuesday, Nov 13th, during class. What will not be covered: Pumping lemma for CFLs; non-context-free languages. What may be covered: anything else. Anything from midterm #1. Nonregular languages & the first pumping lemma. CFLs, CFGs, top-down parsing, derivations, parse trees, ambiguity/refactoring, regular grammars, CNF, PDAs, etc.
Exercise Problem: Which two grammars denote the same L? 𝑆→x𝑈x|𝑈 𝑇→𝑇xx|xx 𝑈→𝑈x|xx𝑈 𝑆→𝑉xx 𝑆→𝐴xx 𝑉→𝑉x|x 𝐴→x 𝑆→𝑆xx|x𝐴x 𝑆→x𝑆x|𝐴 𝐴→x 𝐴→x
Exercise Problem: Which two grammars denote the same L? 𝑆→x𝑈x|𝑈 𝑇→𝑇xx|xx 𝑈→𝑈x|xx𝑈 𝑆→𝑉xx 𝑆→𝐴xx 𝑉→𝑉x|x 𝐴→x 𝑆→𝑆xx|x𝐴x 𝑆→x𝑆x|𝐴 𝐴→x 𝐴→x
Exercise Problem: Which grammars are regular? 𝑆→xx𝑆𝑉|𝑉 𝑆→xyz𝐴 𝑉→𝑉x|x 𝐴→zz|𝑆 𝑆→x𝑇 𝑆→x𝑈x|𝑈 𝑇→𝑇xy𝑇|yx 𝑈→𝑈x|xx𝑈 𝑆→𝑆xx|x𝐴x 𝑆→xy𝑆|yz𝑅 𝐴→x 𝑅→xz𝑅|zz|𝜖
Exercise Problem: Which grammars are regular? 𝑆→xx𝑆𝑉|𝑉 𝑆→xyz𝐴 𝑉→𝑉x|x 𝐴→zz|𝑆 𝑆→x𝑇 𝑆→x𝑈x|𝑈 𝑇→𝑇xy𝑇|yx 𝑈→𝑈x|xx𝑈 𝑆→𝑆xx|x𝐴x 𝑆→xy𝑆|yz𝑅 𝐴→x 𝑅→xz𝑅|zz|𝜖
Exercise Problem: Find a regular grammar for a(b*a)*.
Exercise Problem: Find a regular grammar for a(b*a)*.
Exercise Problem: Explicitly left-factor the following grammar: 𝑆→ab|a𝑆|b
Exercise Problem: Explicitly left-factor the following grammar: 𝑆→ab|a𝑆|b 𝑆→a𝑇|b 𝑇→b|a𝑆
Exercise Problem: Explicitly left-factor the following grammar: 𝑆→ab𝑇|aa𝑉 𝑇→b𝑆|b𝑉|c 𝑉→a|b
Exercise Problem: Explicitly left-factor the following grammar: 𝑆→ab𝑇|aa𝑉 𝑇→b𝑆|b𝑉|c 𝑉→a|b 𝑆→a 𝑆 ′ 𝑆 ′ →b𝑇|a𝑉 𝑇→b 𝑇 ′ |c 𝑇 ′ →a 𝑇 ′′ |b 𝑉→a|b 𝑇 ′′ →b𝑇|a𝑉|𝜖
Exercise Problem: Diagram an empty-stack-accepting PDA, where |Q| = 1, that accepts the language of even-length strings over {a}. q0 ?
a,A/𝜖 a, Z 0 / AZ 0 𝜖, Z 0 /𝜖 ⟨{ 𝑞 0 },{a},{A, Z 0 },𝛿, 𝑞 0 , Z 0 ,Ø⟩ Exercise Problem: Diagram an empty-stack-accepting PDA, where |Q| = 1, that accepts the language of even-length strings over {a}. q0 a,A/𝜖 a, Z 0 / AZ 0 𝜖, Z 0 /𝜖 𝛿={( 𝑞 0 ,a,A,{( 𝑞 0 ,𝜖)}),( 𝑞 0 ,a, Z 0 ,{( 𝑞 0 , AZ 0 )}),( 𝑞 0 ,𝜖, Z 0 ,{( 𝑞 0 ,𝜖)})} ⟨{ 𝑞 0 },{a},{A, Z 0 },𝛿, 𝑞 0 , Z 0 ,Ø⟩
Exercise Problem: Define a grammar, over terminals {[,]}, in regex [*]*, for the language of mismatched braces.
𝑆→𝐿𝑀|𝑀𝑅 𝑀→[𝑀]|𝜖 𝐿→[𝐿|[ 𝑅→]𝑅|] Exercise Problem: Define a grammar, over terminals {[,]}, in regex [*]*, for the language of mismatched braces. 𝑆→𝐿𝑀|𝑀𝑅 𝑀→[𝑀]|𝜖 𝐿→[𝐿|[ 𝑅→]𝑅|]