CMSC330 Fall 2016 Midterm #2 2:00pm/3:30pm

Similar documents
CMSC 330, Fall 2018 Midterm 2

CMSC330 Spring 2016 Midterm #2 9:30am/12:30pm/3:30pm

CMSC330 Spring 2017 Midterm 2

CMSC330 Fall 2016 Midterm #1 2:00pm/3:30pm

CMSC330 Spring 2014 Midterm #2. Score 1 OCaml types & type

CMSC330 Spring 2018 Midterm 2 9:30am/ 11:00am/ 3:30pm

CMSC330 Fall 2016 Final Exam

CMSC330 Fall 2017 Final Exam

CMSC 330, Fall 2018 Midterm 2

CMSC330 Spring 2016 Final Exam

CMSC330 Spring 2017 Midterm #1 9:30am/11:00am/12:30pm/5:00pm

CMSC330 Spring 2017 Midterm #1 Solution

CMSC330 Spring 2016 Midterm #1 9:30am/12:30pm/3:30pm

CMSC330 Fall 2017 Final Exam Solution

Fall 2013 Midterm Exam 10/22/13. This is a closed-book, closed-notes exam. Problem Points Score. Various definitions are provided in the exam.

CMSC330 Fall 2014 Midterm 2 Solutions

CMSC330 Spring 2016 Midterm #1 9:30am/12:30pm/3:30pm Solution

Midterm I - Solution CS164, Spring 2014

Midterm I (Solutions) CS164, Spring 2002

CMSC330 Spring 2014 Midterm 2 Solutions

CMSC330 Spring 2015 Midterm #1 9:30am/11:00am/12:30pm

CMSC330 Spring 2015 Final Exam 9:30am/11:00am/12:30pm

CMSC330 Spring 2015 Midterm #1 9:30am/11:00am/12:30pm

CMSC330 Spring 2008 Final Exam

Denotational Semantics; Lambda Calculus Basics Section and Practice Problems Week 4: Tue Feb 13 Fri Feb 16, 2018

CIS 500 Software Foundations Midterm I

Concepts of programming languages

CMSC330 Fall 2009 Final Exam

CMSC330 Fall 2015 Midterm #1 12:30pm/2:00pm/5:00pm

CIS 500 Software Foundations Fall September 25

CS 4110 Programming Languages & Logics. Lecture 17 Programming in the λ-calculus

1. Consider the following program in a PCAT-like language.

Whereweare. CS-XXX: Graduate Programming Languages. Lecture 7 Lambda Calculus. Adding data structures. Data + Code. What about functions

CIS 500 Software Foundations Midterm I Answer key October 8, 2003

UVa ID: NAME (print): CS 4501 LDI Midterm 1

Type Systems Winter Semester 2006

CMSC330 Spring 2012 Final Exam Solutions

The Lambda Calculus. 27 September. Fall Software Foundations CIS 500. The lambda-calculus. Announcements

Problem Score Max Score 1 Syntax directed translation & type

CS/ECE 374 Fall Homework 1. Due Tuesday, September 6, 2016 at 8pm

CS 4240: Compilers and Interpreters Project Phase 1: Scanner and Parser Due Date: October 4 th 2015 (11:59 pm) (via T-square)

Harvard School of Engineering and Applied Sciences CS 152: Programming Languages. Lambda calculus

CMSC330 Fall 2014 Final Exam

CMSC 330 Exam #2 Fall 2008

CS152: Programming Languages. Lecture 7 Lambda Calculus. Dan Grossman Spring 2011

CMSC330 Fall 2014 Midterm 1 Solution

Chapter 5: The Untyped Lambda Calculus

CMSC330 Fall 2014 Midterm 1 Grading

Translator Design CRN Test 3 Revision 1 CMSC 4173 Spring 2012

Introduction to the Lambda Calculus

I have read and understand all of the instructions below, and I will obey the Academic Honor Code.

CS143 Midterm Fall 2008

CMPUT 325 : Lambda Calculus Basics. Lambda Calculus. Dr. B. Price and Dr. R. Greiner. 13th October 2004

Theory of Computation Dr. Weiss Extra Practice Exam Solutions

CMSC330 Spring 2015 Final Exam 9:30am/11:00am/12:30pm

Midterm Exam II CIS 341: Foundations of Computer Science II Spring 2006, day section Prof. Marvin K. Nakayama

MIDTERM EXAMINATION. CSE 130: Principles of Programming Languages. Professor Goguen. February 16, points total

Functional Programming

CMSC 330: Organization of Programming Languages. Lambda Calculus

First Midterm Exam CS164, Fall 2007 Oct 2, 2007

CS 2210 Sample Midterm. 1. Determine if each of the following claims is true (T) or false (F).

COP4020 Spring 2011 Midterm Exam

UNIVERSITY OF TORONTO Faculty of Arts and Science. Midterm Sample Solutions CSC324H1 Duration: 50 minutes Instructor(s): David Liu.

CMSC 330: Organization of Programming Languages

ECE251 Midterm practice questions, Fall 2010

11. a b c d e. 12. a b c d e. 13. a b c d e. 14. a b c d e. 15. a b c d e

Functional Languages and Higher-Order Functions

CMSC 330: Organization of Programming Languages. Lambda Calculus

CMSC 330: Organization of Programming Languages. Operational Semantics

11/6/17. Outline. FP Foundations, Scheme. Imperative Languages. Functional Programming. Mathematical Foundations. Mathematical Foundations

Programming Language Features. CMSC 330: Organization of Programming Languages. Turing Completeness. Turing Machine.

CMSC 330: Organization of Programming Languages

ECE 468/573 Midterm 1 September 30, 2015

University of Nevada, Las Vegas Computer Science 456/656 Fall 2016

CSE P 501 Exam 8/5/04

9/23/2014. Why study? Lambda calculus. Church Rosser theorem Completeness of Lambda Calculus: Turing Complete

CMSC 330, Fall 2018 Midterm 1

CSE 5317 Midterm Examination 4 March Solutions

ECE 468/573 Midterm 1 October 1, 2014

Lecture #3: Lambda Calculus. Last modified: Sat Mar 25 04:05: CS198: Extra Lecture #3 1

CSE 582 Autumn 2002 Exam 11/26/02

CSE-321 Programming Languages 2012 Midterm

Homework 1 Due Tuesday, January 30, 2018 at 8pm

CSE 401/M501 18au Midterm Exam 11/2/18. Name ID #

15-110: Principles of Computing, Spring 2018

CMSC330 Fall 2016 Final Exam Solution

CSE-321 Programming Languages 2010 Midterm

1. [5 points each] True or False. If the question is currently open, write O or Open.

More Lambda Calculus and Intro to Type Systems

Midterm 2. CMSC 430 Introduction to Compilers Fall Instructions Total 100. Name: November 21, 2016

Tail Calls. CMSC 330: Organization of Programming Languages. Tail Recursion. Tail Recursion (cont d) Names and Binding. Tail Recursion (cont d)

cs1120: Exam 1 Due: Wednesday, 06 October at 3:30pm (in class)

CIS 110 Introduction To Computer Programming. February 29, 2012 Midterm

Fundamentals and lambda calculus

cs1120: Exam 1 Due: Wednesday, 06 October at 3:30pm (in class)

Pure Lambda Calculus. Lecture 17

UMBC CMSC 331 Final Exam

MIDTERM EXAM (Solutions)

CSE505, Fall 2012, Midterm Examination October 30, 2012

CSE 332 Autumn 2013: Midterm Exam (closed book, closed notes, no calculators)

Transcription:

CMSC330 Fall 2016 Midterm #2 2:00pm/3:30pm Gradescope ID: (Gradescope ID is the First letter of your last name and last 5 digits of your UID) (If you write your name on the test, or your gradescope ID is not correct, your test will NOT be graded) Discussion Time: 10am 11am 12pm 1pm 2pm 3pm TA Name (Circle): Alex Austin Ayman Brian Damien Daniel K. Daniel P. Greg Tammy Tim Vitung Will K. Instructions 1. Do not start this test until you are told to do so! 2. You have 75 minutes to take this midterm. 3. This exam has a total of 100 points, so allocate 45 seconds for each point. 4. This is a closed book exam. No notes or other aids are allowed. 5. Answer short answer questions concisely in one or two sentences. 6. For partial credit, show all of your work and clearly indicate your answers. 7. Write neatly. Credit cannot be given for illegible answers. Problem Score 1 Finite Automata /20 2 Context Free Grammars /16 3 Parsing /8 4 OCaml /20 5 Programming Language Concepts /12 6 Operational Semantics /10 7 Lambda Calculus /14 Total /100 1

1. Finite Automata (20 pts) Figure 1: NFA A. (5 pts) Convert the NFA in Figure 1 to a DFA. B. (5 pts) Write a regular expression that accepts the same language as the NFA shown in Figure 1. 2

C. (5 pts) Construct a DFA or NFA that accepts the set of strings over {a, b} that contain exactly two b s. D. (5 pts) Reduce the following DFA to Regular Expression. (Hint: delete states 2, 1, and 0 in that order.) 3

2. Context Free Grammars (16 pts) A. (3 pts) The following context-free grammar generates all strings of the form a x b y for some x and y: S -> at T -> atbb ε Define an equation relating x and y. B. (6 pts) Give a context-free grammar for binary number expressions involving &, +, and ~ (and, or, not) 1) Order of precedence (highest to lowest): ~, &, + 2) Associativity for & and + is left, ~ is unary 3) Parenthesis should be supported 4) Binary numbers can start with 0 s (1 and 01 are valid) C. (4 pts) Let G be the context-free grammar S as Sb SS ab a) Give a regular expression for the language of G. G. b) Prove that G is ambiguous. Give an unambiguous grammar that generates the same language as 4

D. (3 pts) Give a context-free grammar G that generates the language L = L 1 L 2, where L 1 = {a n b n c m : n, m > 0} L 2 = {a n b m c m : n, m > 0} 3. Parsing (8 pts) A. (3 pts) Consider the following context-free grammar: S (A) a A S B B ; S B ε Compute the first sets of each non-terminal FIRST(S) = { } FIRST(A) = { } FIRST(B) = { } B. (5 pts) Consider the following CFG. S E; S E E T O E T T n O + - Draw a parse tree for the string n+n;n-n 5

4. OCaml (20 pts) let rec map f l = match l with [] -> [] h::t -> let r = f h in r :: map f t ;; let rec fold f a l = match l with [] -> a h::t -> fold f (f a h) t ;; helper methods are allowed. A. (8 points) Write a function combine that, given a list of potentially overlapping intervals (pairs) sorted by the first element of each pair, return a list with the overlapping pairs from the original list having been combined. combine [(1,3);(3,5);(7,9)] = [(1,5);(7,9)] combine [(1,3);(4,8);(5,9)] = [(1,3);(4,9)] let rec combine lst = 6

let rec rotate lst = B. (8 points) Write a function rotate that, given a list and a positive integer k, rotate the list k elements to the left. You are alloawed to use @ to merge lists. rotate 2 [1;2;3;4;5] = [3;4;5;1;2] rotate 0 [1;2;3;4;5] = [1;2;3;4;5] rotate 8 [1;2;3;4;5] = [3;4;5;1;2] C. (4 points) Using fold and/or map, write a function to compute the sum of squares each item in a list of floating point values. square_sum [1.5;4.0;2.0] = 22.25 square_sum [1.0;2.0;3.0] = 14.00 let rec square_sum lst = 7

5. Programming Language Concepts (12 pts) A. (4 pts) The following code calculates 1+2+3+4 n. It is not tail recursive. Rewrite the function sum, so that it is tail recursive. (You are allowed to add nested helper functions) let rec sum n = if n=1 then 1 else n + sum(n-1) let rec sum n = B. (2 pts) Circle all of the statements that apply to the following OCaml pseudocode: let x = E1 in let x = E2 in E3 a) In the scope of E1, x is bound b) In the scope of E2, x is bound c) The pseudocode contains an instance of shadowing d) The code is invalid, as there are multiple declarations of x C. (1 pts) Which of the following statements is NOT true about a language with first-class functions? a) Functions can be passed in as arguments to other functions b) Functions can be returned as the result of calling other functions c) The language does not include imperative features d) The language treats functions on the same level as other data types D. (1 pts) The fixed-point combinator is used to achieve. E. (1 pts) type checking occurs during a program s compilation. F. (1 pts) True / False Statically typed languages are type safe. G. (2 pts) True / False I voted. 8

6. Operational Semantics (10 pts) Use the language defined by the context-free grammar and the operational semantics to fill in the blank boxes in the following two derivations: 9

7. Lambda Calculus (14 pts) A. Alpha Equivalence (2 point each): For each pair of expressions, determine if they are alpha equivalent. Circle Equivalent or Not Equivalent. λf. λx. f (f x y) y λf. λx. f (f x z) z Equivalent Not Equivalent λa. λb. (λa. a b) (λb. b b) a λa. λx. (λa. a x) (λb. x x) a Equivalent Not Equivalent B. Beta Reduction: Reduce each expression to normal form. If it reduces infinitely, state that it does not reduce. (2 points) λx. (λz. z z x) a b (3 points) (λx. λy. y x y) (a b) (λm. a m) C. Operations on Church Numerals (5 points): Given the following definitions, prove that mult 2 * 0 = 0. Show all of your beta reductions and alpha conversions for full points. 0 = λf.λy. y 2 = λf.λy. f (f y) mult =λm. λn. λ f. M (N f) Prove mult 2 * 0 = 0 10