final-soln-fall09 - CMSC330 Fall 2009 Final Exam Solutions...

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

View Full Document Right Arrow Icon
CMSC330 Fall 2009 Final Exam Solutions 1. (9 pts) Programming languages a. (3 pts) Briefly describe the difference between syntax and semantics of programming languages. Syntax refers to the program text, semantics refers to the program meaning. b. (3 pts) Explain briefly what type inference is. A compile-time algorithm for determining the type of a variable through its use. c. (3 pts) List one of two possible scoping rules we discussed in class, and briefly describe a disadvantage for this approach. Dynamic scoping – confusing semantics Static scoping – implementation complexity 2. (6 pts) Ruby What is the output (if any) of the following Ruby programs? Write FAIL if code does not execute. a. “CMSC 330” =~ /([a-zA-Z]+)/ # Output = CMSC puts $1 b. a = { 1 => 2 } # Output = 2 a.keys.each{ |x| puts a[x] } 3. (12 pts) Regular expressions, context-free grammars, and finite automata a. (6 pts) Convert the following NFA to a DFA using the subset construction algorithm. Be sure to label each state in the DFA with the corresponding state(s) in the NFA. Original NFA Resulting DFA 3 a 2 1 b 4 a ε ε b 1,3 2,4 a,b 3 a a b. (3 pts) Write a regular expression for the NFA above (a|b)(aa)* c. (3 pts) Write a context-free grammar for all binary numbers (strings consisting of 0s and 1s) of the form 0 n 1 m , where n = m+2 and m 0. E,g,: 00, 0001, 00000111 S 00A OR S 0S1 | 00 A 0A1 | epsilon
Background image of page 1

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

View Full DocumentRight Arrow Icon
4. (6 pts) OCaml types and type inference a. (3 pts) Give the type of f in the following OCaml expression let f x y = x + y in f 3 4 Type = int -> int -> int b. (3 pts) Write an OCaml expression with the following type ‘a -> 'a Code = fun x -> x OR let f x = x 5. (6 pts) Lambda calculus (3 pts each) Evaluate the following λ -expressions as much as possible a. ( λ x.x) ( λ y.y) ( λ z.z) ( λ x.x) ( λ y.y) ( λ z.z) ( λ y.y) ( λ z.z)
Background image of page 2
Image of page 3
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 / 6

final-soln-fall09 - CMSC330 Fall 2009 Final Exam Solutions...

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

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