m1-soln-fall11

m1-soln-fall11 - CMSC330 Fall 2011 Midterm #1 Solution 1....

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

View Full Document Right Arrow Icon
CMSC330 Fall 2011 Midterm #1 Solution 1. (6 pts) Programming languages a. (3 pts) List a programming language feature that makes it easier to write programs, but make it more difficult to detect errors in the program. Explain why. Implicit declarations (misspelled variable names), dynamic types (type errors), weak typing (type errors), etc… b. (3 pts) What language feature in Ruby is similar to anonymous functions in OCaml / Java? Explain. Code blocks, since they define unnamed functions that can be passed to methods as arguments. 2. (6 pts) Ruby What is the output (if any) of the following Ruby programs? Write FAIL if code does not execute. a. (2 pts) a = “foo” # Output = oo if a =~ /(o+)/ then puts $1 end b. (2 pts) a = [ ] # Output = FAIL a[“foo”] = 1 puts a[“foo”] c. (2 pts) a = { } # Output = 1 a[“foo”] = 1 nil puts a[“foo”] puts a[“bar”] 3. (10 pts) Regular expressions and finite automata For this problem, provide regular expressions using only the concatenate, union, and closure operations. I.e., do not use Ruby regular expressions. a. (4 pts) Give a regular expression for the set of strings accepted by the following NFA: RE = (b|a)(aa)* b a ± 1 2 3 4 ± a
Background image of page 1

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

View Full DocumentRight Arrow Icon
b. (6 pts) Give a regular expression for OCaml expressions of type
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.

Page1 / 5

m1-soln-fall11 - CMSC330 Fall 2011 Midterm #1 Solution 1....

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