DOC PREVIEW
UMD CMSC 330 - Homework #2

This preview shows page 1 out of 2 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 2 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 2 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

CMSC 330 Fall 2007Homework 2: Grammars, OCAMLPosted on: Saturday, Oct. 20, 2007Due: Tuesday, Oct. 30 9:20A M, 2007Homework should be submitted in my office (4115 AVW) BEFORE 9:20AM (slip themunder my door if it is closed). Homework will not be accepted after 9:20AM as the homeworkproblems may be reviewed in class that day. No late homework is accepted. Late home-work will receive no credit. Be sure to label the problem you are solving clearly withthe problem number and subsection. Typing your homework is not required, but homeworkshould be legible. Illegible solutions will receive no credit. Be sure to put your nameon the homework.Remember, you must do this homework on your own, without any external sources. Ifyou are unsure what is allowed, please contact the instructor.1. Creating GrammarsWrite unambiguous grammars for the following languages:(a) {anbn|n ≥ 0 and n is odd}(b) All valid OCaml lists created using ::. Make sure your construction correctlyshows the right association of this operator. Use v(′a) to indicate a value of type′a. Examples of valid strings in this language: 1 :: [], [], “hi” :: “there” :: [](c) All valid OCaml guards for if statements in the abbreviated language containingterminals:(, ), ||, &&, <, >, =. Parenthesis must be appropriately matched with every open-ing left parenthesis followed by a closing right par enthesis. ( and ) have thehighest precedence, followed by && and || and the lowest precedence is given to<, >, = etc. Use v(′a) to indicate a value of type of type′a. Note: Yo u don’tneed to worry about type compatibility. Assume that this is done separately.2. Ambiguity ProofsProve that the following grammar is ambiguous. Note: In class, we did not constructformal “proofs” for unambiguous grammars; however, for ambiguous grammars, weused example strings and the definition of a mbiguity.1S → ST |SU |cT → Ub|bU → aT |a3. OCaml Types(a) What is the type of the following OCaml function? Explain why this type iscorrect. (Yes, you can get the answer to the first part by typing this into acomputer... but you will need to know how to do this without a computer for theexam, so think about it anyway.)let rec func (f, l1, l2) = match l1 with[] -> []| (h1::t1) -> match l2 with[] -> [f h1]|(h2::t2) -> [f h1; f h2](b) Make a function that has the following type:func : (’a -> ’b) * (’c * ’c -> ’a) * ’c -> ’bYou may check your answer using your computer, but make sure you can do itwithout this


View Full Document

UMD CMSC 330 - Homework #2

Documents in this Course
Exam #1

Exam #1

6 pages

Quiz #1

Quiz #1

2 pages

Midterm 2

Midterm 2

12 pages

Exam #2

Exam #2

7 pages

Ocaml

Ocaml

7 pages

Parsing

Parsing

38 pages

Threads

Threads

12 pages

Ruby

Ruby

7 pages

Quiz #3

Quiz #3

2 pages

Threads

Threads

7 pages

Quiz #4

Quiz #4

2 pages

Exam #2

Exam #2

6 pages

Exam #1

Exam #1

6 pages

Threads

Threads

34 pages

Quiz #4

Quiz #4

2 pages

Threads

Threads

26 pages

Exam #2

Exam #2

9 pages

Exam #2

Exam #2

6 pages

Load more
Download Homework #2
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Homework #2 and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Homework #2 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?