This preview has intentionally blurred sections. Sign up to view the full version.View Full Document
Unformatted text preview: describe the error. (fun x -> if (x > 0) then x+1) 1 Value/Error = d. (6 pts) Using fold and an anonymous function, write a function attendance which when applied to a list lst of bools, returns the number of elements of lst that are true. Example: attendance [true; false; false; true; true] = 3 let rec fold f a l = match l with -> a | (h::t) -> fold f (f a h) t 2. (8 pts) Context free grammars a. (2 pts) Write a grammar for a x b y , where x = y+3 (i.e., exactly 3 more a’s than b’s) b. (6 pts) Consider the following grammar (where S = start symbol and terminals = [ , ] , ; , e ): S & [ A ] | epsilon A & A ; S | e i. (3 pts) Present a derivation for the string [e;[e;]] ii. (3 pts) Show the parse tree for your derivation...
View Full Document
- Fall '08
- 3 pts, 6 pts, 2 pts, 12 pts, 8 pts, Formal grammar