Homework #1 Solution Sketches: 1) [^aeiou]*a[^aeiou]*e[^aeiou]*i[^aeiou]o*[^aeiou]*u[^aeiou]*, where [^aeiou] represents any alphabetic character other than a e i o u (i.e., a consonant). -> aeiou -> | epsilon -> b | c | d .... 2) The grammar generates strings of even lengths containing the same number of a's and b's (including the null string) (e.g., ~, ab, ba, aaabbb, aabbabaaabbb). 3) The following statement has two distinct parse trees which illustrate that the grammar which it was generated from is ambiguous. if Cond1 then if Cond2 then S1 else if Cond3 then S2 else S3 Parse 1: -> -> if then else -> if then if then else else -> if then if then else else -> if then if then else else -> if then if then else else -> if then if then else if then else -> if then if then else if then else -> if then if then else if then else Parse 2: -> if then -> if then -> if then if then else -> if then if then else -> if then if then else -> if then if then else if then else -> if then if then else if then else -> if then if then else if then else -> if then if then else if then else 4) No, because the grammar involves the concept of memory. Regular expressions cannot describe constructs involving remembering something. 5) Trivial. Consider the sentence: 3 + 4 + 5 Parse 1: (leftmost derivation) -> -> + -> + + (where first in line 2 is expanded to + ) -> + + -> + + -> + + -> 3 + + -> 3 + 4 + -> 3 + 4 + 5 Parse 2: (rightmost derivation) -> -> + -> + + (where second in line 2 is expanded to + ) -> + + -> + + -> + + -> + + <5> -> + 4 + 5 -> 3 + 4 + 5 6) a) {b < 1} a = 2*b + 1 {a < 3} b = a - 3 {b < 0} b) {2b + a > 1} = {b > (1-a)/2} a = 3*(2*b + a) {a > 3} b = 2*a -1 {b > 5}