Download presentation
Presentation is loading. Please wait.
1
Midterm #2 — Review problems
CS 350 — Fall 2018 gilray.org/classes/fall2018/cs350/
2
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.
3
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
4
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
5
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|𝜖
6
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|𝜖
7
Exercise Problem: Find a regular grammar for a(b*a)*.
8
Exercise Problem: Find a regular grammar for a(b*a)*.
9
Exercise Problem: Explicitly left-factor the following grammar:
𝑆→ab|a𝑆|b
10
Exercise Problem: Explicitly left-factor the following grammar:
𝑆→ab|a𝑆|b 𝑆→a𝑇|b 𝑇→b|a𝑆
11
Exercise Problem: Explicitly left-factor the following grammar:
𝑆→ab𝑇|aa𝑉 𝑇→b𝑆|b𝑉|c 𝑉→a|b
12
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𝑉|𝜖
13
Exercise Problem: Diagram an empty-stack-accepting PDA, where |Q| = 1, that accepts the language of even-length strings over {a}. q0 ?
14
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 ,Ø⟩
15
Exercise Problem: Define a grammar, over terminals {[,]}, in regex [*]*, for the language of mismatched braces.
16
𝑆→𝐿𝑀|𝑀𝑅 𝑀→[𝑀]|𝜖 𝐿→[𝐿|[ 𝑅→]𝑅|]
Exercise Problem: Define a grammar, over terminals {[,]}, in regex [*]*, for the language of mismatched braces. 𝑆→𝐿𝑀|𝑀𝑅 𝑀→[𝑀]|𝜖 𝐿→[𝐿|[ 𝑅→]𝑅|]
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.