

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!


page 1 of 2 Exam I Open book/notes
1. [20 points] In each part of this problem, there is an extended BNF expression (terminal character set = {a, b}) and a syntax diagram. Determine whether or not the pair is equivalent, and either explain the equivalence, or if they are not equivalent, give an example of a string that is described by one but not the other. 2. [25 points] Write the Haskell definition of a function 'delSpaces' that accepts one argument that is a string (i.e., [char]), and returns a value that is a copy of the argument string with all spaces deleted. For example, delSpaces "now is the time " = "nowisthetime". Your solution will not receive full credit without an explanation of its operation and justification that it behaves as required. (a) (a* b)* a (^) b (b) (abab)* aba (^) a b a b
page 2 of 2
3. [25 points] For the Haskell expression below, show its derivation tree (from
qop(n,4)^ Æ < | > (non-assoc, prec 4)
exp^10 Æ fexp fexp Æ [ fexp ] aexp
qvar Æ identifier literal Æ numeral | charconst | stringconst | boolconst (partial) Haskell EBNF
4. [30 points] Provide a Haskell definition of a polymorphic function 'replace' that takes three arguments — values x and y of polymorphic type 'a' and a list xs of type [a] — and returns the list xs with each occurrence of x replaced by y, and other elements unchanged. For instance, replace 's' 'l' "bass" yields "ball". Your solution will not receive full credit without an explanation of its operation and justification that it behaves as required.