Unformatted text preview: let getFirsts lst = map (fun a -> match a with (h,t) -> h) lst OR let getFirsts lst = map (fun (h,t) -> h) lst OR let getFirsts lst = fold (fun a y -> match y with (h,t) -> h::a) lst OR let getFirsts lst = fold (fun a (h,t) -> h::a) lst etc… 3. (6 pts) Context free grammars Consider the following grammar: S & aSaS | ± (* epsilon *) a. (2 pts) Describe the set of strings generated by the grammar. Strings of even numbers of a’s. I.e., (aa)* b. (4 pts) Is the grammar ambiguous? Show proof if possible. Grammar is ambiguous since there are 2 leftmost derivations for “aaaa”. S ± aSaS ± aaS ²± aaaSaS ± aaaaS ± aaaa S ± aSaS ± aaSaSaS ± aaaSaS ± aaaaS ± aaaa let rec map f l = match l with -> | (h::t) -> (f h)::(map f t) let rec fold f a l = match l with -> a | (h::t) -> fold f (f a h) t...
View Full Document
- Fall '08
- Functional Programming, Type theory, Context-free grammar, following OCaml expression