1. Write a regular expression to denote the set of all strings of digits with no repeated digit. 2. Write a grammar to generate the set of all strings of digits with at most one repeated digit. 3. Write a grammar to generate the set of all strings of 0s and 1s with an even number of 0s and an odd number of 1s. 4. Write a regular expression to denote the set of all strings of 0s and 1s with an even number of 0s and an odd number of 1s. 5. Write a ML function that flips alternate elements of a list. That is, given a list [a1,a2,..,an] as arguments, produce [a2,a1,a4,a3,a6,a5,...]. If n is odd, an remains at the end. 6. Write a recursive ML function to find the cube of an integer. 7. Suppose we define a ML function f by a statement that begins: fun f(a:int, b, c, d, e) = .... Tell what can be inferred about the types of b,c,d, and/or e if the body of the function is each of the following if-then-else statements: i) if a -> or | -> and | -> not | ( ) | true | false Construct a parse tree for the sentence "not (true or false)". Is the grammar ambiguous? 11. Consider the grammar S -> aSbS | bSaS | epsilon where 'epsilon' is the empty symbol. Show that this grammar is ambiguous. What language does the grammar generate? 12. Using map, foldr, and/or foldl, write a definition of the ML function implode, which turns a list of characters into a single string with those characters in order. 13. Using map, foldr, and/or foldl, write a definition of the ML function concat, which turns a list of strings into the concatenation of all those strings. 14. If we defined fun F x = x+3; fun G x = y*y + 2*y; what mathematical function is denoted by G o F? 15. What is the difference between the following two definitions of F? fun F x y = x+y; fun F(x,y) = x+y; 16. Write an ML function that takes a list of integers as argument and returns a pair consisting of the sum of the even positions and the sum of the odd positions of the list. You should not use any auxiliary functions. 17. A function definition, when processed in ML, produces the following response: val mystery = fn: int list -> int list -> int list What can you say about mystery? 18. Write a recursive ML function that given an integer i and a list L, cycles L i times. That is, if L = [a_1,a_2,...,a_n] then the desired result is [a_(i+1), a_(i+2), ..., a_n, a_1, a_2, ..., a_i]. 19. Write a recursive ML function sumLists that takes as argument a list whose elements are themselves lists of integers, and returns the sum of the integers found among all of the lists. What is the type of sumLists? 20. Mention two solutions to the "garbage" problem. 21. Mention two solutions to the "dangling pointers" problem. 22. Is the language L given by: L = {ww : w is a string of 0s and 1s} context-free or context-sensitive? 23. What form of type equivalence (name/structural/declaration) does Java use? 24. APL uses right associativity for evaluating expressions. For instance 2-3-4 is evaluated as 2-(3-4). Write a grammar for APL expressions that capture this property. Assume you are given: -> generates all numbers -> + | - | * | / Your grammar should use as the start symbol. 25. Problem 11 of Chapter 5 of your textbook. 26. Problem 12 of Chapter 5 of your textbook. 27. Problem 13 of Chapter 5 of your textbook. 28. Problem 14 of Chapter 5 of your textbook. 29. Name five features of ML not present in a language like C. 30. Problem 19 of Chapter 7 of your textbook. 31. Write a Pascal function sand which takes two booleans a, b, and returns the AND of a and b, via short circuit evaluation. 32. Write a Pascal function sor which takes two booleans a, b, and returns the OR of a and b, via short circuit evaluation. 33. Is it possible to have short-circuit evaluation for XOR? Why/why not? 34. Is it possible to have short-circuit evaluation for the arithmetic * operator (multiplication)? Under what conditions? 35. Give two examples of ordinal types in Pascal. 36. Infer the type of the function mkpairs fun mkpairs [] = [] | mkpairs (x::y) = (x,x) :: (mkpairs y); 37. Rewrite the following infix expression in prefix and postfix. (3 - 4) / 5 + 6 * 7 38. In the following code type ar1 = array [1..10] of integer; type ar2 = ar1; type ar3 = array [1..10] of integer; which types would be considered equivalent under structural equivalence rules? under name equivalence rules? under declaration equivalence rules? 39. Mention 5 "binding times" and arrange them in order of earliest to latest. 40. Consider the function written in some "mystery" language function try(a,b) = if a=0 return 1 else return b; Assume we employ try in the expression try(0,1/0) Is it advisable that mystery use normal-order evaluation or applicative-order evaluation? ----- new for final 41. know how to use non-deterministic guarded-do and guarded-if constructs to write given constructs (see Homework #7) 42. know concepts from oop and how Smalltalk does oop 43. be able to write Prolog predicates and ML functions, often recursively 44. know how cut in Prolog works 45. know how the various parameter passing mechanisms work 46. know topics covered on the last day we had a lecture