final-soln-spr09

final-soln-spr09 - CMSC330 Spring 2009 Final Exam...

Info iconThis preview shows pages 1–5. Sign up to view the full content.

View Full Document Right Arrow Icon
CMSC330 Spring 2009 Final Exam (Solutions) Problem Score Max Score 1 Programming languages 14 2 Regular expressions & CFGs 8 3 Finite automata 10 4 Parsing 12 5 OCaml types & type inference 12 6 OCaml programming 10 7 Scoping 8 8 Polymorphism 9 9 Multithreading 20 10 Lambda calculus 16 11 Lambda calculus encodings 16 12 Operational semantics 8 13 Markup languages 8 14 Garbage collection 9 Total 160
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
1. (14 pts) Programming languages a. (6 pts) List 3 different design choices for parameter passing in a programming language. Which choice is seldom used in modern programming languages? Explain why. Design choices (need 3) = call-by-value, call-by-reference, call-by-name, call-by-result, call-by-value-result, call-by-need Seldom used = everything except call-by-value or call-by-reference Reason = highly complex, inefficient, can be confusing b. List 2 different design choices for type declarations in a programming language. Which choice is seldom used in modern programming languages? Explain why. Design choices (need 2) = explicit, implicit Seldom used = implicit Reason = requires static types, requires type inference, error messages can be confusing c. List 2 different design choices for determining scoping in a programming language. Which choice is seldom used in modern programming languages? Explain why. Design choices (need 2) = static lexical, dynamic Seldom used = dynamic Reason = can be confusing 2. (8 pts) Regular expressions and context free grammars Give a a. Regular expression for binary numbers with an even number of 1s. (0*10*10*)*| 0* b. Context free grammar for binary numbers with twice as many 1s as 0s S S1S1S0S | S1S0S1S | S0S1S1S | epsilon Many possible answers, one possible solution above.
Background image of page 2
3. (10 pts) Finite automata Apply the subset construction algorithm to convert the following NFA to a DFA. Show the NFA states associated with each state in your DFA. Answer 1 1 0 2 3 0 ε 1 1 0 2 1, 2,3 0 1
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
(12 pts) Parsing Consider the following grammar: S Ac | a A bS | epsilon a. (6 pts) Compute First sets for S and A First(S) = { a, b, c } // First(A) = { b, epsilon } // b. (6 pts) Write the parse_A( ) function for a predictive, recursive descent parser for the grammar (You may assume parse_S( ) has already been written, and match( ) is provided). parse_A( ) { if (lookahead == ‘b’) { // for correct lookahead match(‘b’); // for correct body parse_S( ); } else ; // just return for other lookaheads } 5. (12 pts) OCaml Types and Type Inference a. Give the type of the following OCaml expression let f x y z = y (x z) Type = ('a -> 'b) -> ('b -> 'c) -> 'a -> 'c // b. (6 pts) Write an OCaml expression with the following type int -> (int * int -> 'a) -> 'a Code = let f x y = y (2, x+1) c. Give the value of the following OCaml expression. If an error exists, describe the error.
Background image of page 4
Image of page 5
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 01/13/2012 for the course CMSC 330 taught by Professor Staff during the Fall '08 term at Maryland.

Page1 / 11

final-soln-spr09 - CMSC330 Spring 2009 Final Exam...

This preview shows document pages 1 - 5. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online