low and not larger than high. 18 points

Similar documents
Test 1 Summer 2014 Multiple Choice. Write your answer to the LEFT of each problem. 5 points each 1. Preprocessor macros are associated with: A. C B.

The results for a few specific cases below are indicated. allequal ([1,1,1,1]) should return true allequal ([1,1,2,1]) should return false

CSE 3302 Notes 5: Memory Management

Principles of Programming Languages Topic: Scope and Memory Professor Louis Steinberg Fall 2004

LECTURE 17. Expressions and Assignment

CSE 3302 Notes 6: Data Types

CS 415 Midterm Exam Spring SOLUTION

CSE 413 Midterm, May 6, 2011 Sample Solution Page 1 of 8

Functional Programming. Pure Functional Programming

Question No: 1 ( Marks: 1 ) - Please choose one One difference LISP and PROLOG is. AI Puzzle Game All f the given

CS 314 Principles of Programming Languages

COP4020 Programming Languages. Functional Programming Prof. Robert van Engelen

Final-Term Papers Solved MCQS with Reference

Control in Sequential Languages

Pierce Ch. 3, 8, 11, 15. Type Systems

Expressions and Assignment

Parsing Scheme (+ (* 2 3) 1) * 1

Functional Programming. Big Picture. Design of Programming Languages

NOTE: Answer ANY FOUR of the following 6 sections:

Functional Programming. Pure Functional Languages

G Programming Languages - Fall 2012

Lecture 9: Parameter Passing, Generics and Polymorphism, Exceptions

Racket. CSE341: Programming Languages Lecture 14 Introduction to Racket. Getting started. Racket vs. Scheme. Example.

CS 314 Principles of Programming Languages

Design Issues. Subroutines and Control Abstraction. Subroutines and Control Abstraction. CSC 4101: Programming Languages 1. Textbook, Chapter 8

COP4020 Programming Languages. Subroutines and Parameter Passing Prof. Robert van Engelen

Subprograms. Bilkent University. CS315 Programming Languages Pinar Duygulu

UMBC CMSC 331 Final Exam

Compiler Construction

FORM 2 (Please put your name and form # on the scantron!!!!)

Functional Programming. Pure Functional Languages

CS 360 Programming Languages Interpreters

1. true / false By a compiler we mean a program that translates to code that will run natively on some machine.

Introduction to Programming Using Java (98-388)

Scheme. Functional Programming. Lambda Calculus. CSC 4101: Programming Languages 1. Textbook, Sections , 13.7

CMSC 331 Final Exam Section 0201 December 18, 2000

Compiler Construction

CS 415 Midterm Exam Spring 2002

Scope, Functions, and Storage Management

Compiler Construction

CSE 3302 Notes 7: Control Abstraction

SEMANTIC ANALYSIS TYPES AND DECLARATIONS

MIDTERM EXAM (Solutions)

CPS 506 Comparative Programming Languages. Programming Language Paradigm

CMSC 4023 Chapter 9. Fundamentals of Subprograms Introduction

CS558 Programming Languages

Scheme Tutorial. Introduction. The Structure of Scheme Programs. Syntax

COP4020 Programming Assignment 1 - Spring 2011

Compiler Construction

Concepts Introduced in Chapter 7

User-defined Functions. Conditional Expressions in Scheme

1 Lexical Considerations

Functional Languages. Hwansoo Han

CS 314 Principles of Programming Languages

Programming Languages Third Edition. Chapter 10 Control II Procedures and Environments

COP4020 Programming Languages. Control Flow Prof. Robert van Engelen

G Programming Languages Spring 2010 Lecture 6. Robert Grimm, New York University

SOFTWARE ARCHITECTURE 6. LISP

Chapter 15. Functional Programming Languages

Today's Topics. CISC 458 Winter J.R. Cordy

R13 SET Discuss how producer-consumer problem and Dining philosopher s problem are solved using concurrency in ADA.

CA4003 Compiler Construction Assignment Language Definition

CS 330 Lecture 18. Symbol table. C scope rules. Declarations. Chapter 5 Louden Outline

CSE 5317 Midterm Examination 4 March Solutions

Faculty of Electrical Engineering, Mathematics, and Computer Science Delft University of Technology

LECTURE 16. Functional Programming

Short Notes of CS201

G Programming Languages - Fall 2012

Vectors in Scheme. Data Structures in Scheme

Weeks 6&7: Procedures and Parameter Passing

Organization of Programming Languages CS3200/5200N. Lecture 11

Object Oriented Programming: In this course we began an introduction to programming from an object-oriented approach.

Functional Programming - 2. Higher Order Functions

CS201 - Introduction to Programming Glossary By

Computer Science 21b (Spring Term, 2015) Structure and Interpretation of Computer Programs. Lexical addressing

M/s. Managing distributed workloads. Language Reference Manual. Miranda Li (mjl2206) Benjamin Hanser (bwh2124) Mengdi Lin (ml3567)

Types and Type Inference

Principles of Programming Languages COMP251: Functional Programming in Scheme (and LISP)

Time : 1 Hour Max Marks : 30

Summer 2017 Discussion 10: July 25, Introduction. 2 Primitives and Define

WA1278 Introduction to Java Using Eclipse

Topic IV. Parameters. Chapter 5 of Programming languages: Concepts & constructs by R. Sethi (2ND EDITION). Addison-Wesley, 1996.

Run Time Environment. Procedure Abstraction. The Procedure as a Control Abstraction. The Procedure as a Control Abstraction

Programming Languages Third Edition. Chapter 9 Control I Expressions and Statements

Answer: Early binding generally leads to greater efficiency (compilation approach) Late binding general leads to greater flexibility

CMSC 330: Organization of Programming Languages

Name EID. (calc (parse '{+ {with {x {+ 5 5}} {with {y {- x 3}} {+ y y} } } z } ) )

CSC 533: Programming Languages. Spring 2015

St. MARTIN S ENGINEERING COLLEGE Dhulapally, Secunderabad

Preface... (vii) CHAPTER 1 INTRODUCTION TO COMPUTERS

SCHEME 8. 1 Introduction. 2 Primitives COMPUTER SCIENCE 61A. March 23, 2017

Functions and Recursion. Dr. Philip Cannata 1

Informatica 3 Syntax and Semantics

Functional Languages and Higher-Order Functions

A brief introduction to C programming for Java programmers

11/6/17. Functional programming. FP Foundations, Scheme (2) LISP Data Types. LISP Data Types. LISP Data Types. Scheme. LISP: John McCarthy 1958 MIT

Lexical Considerations

Topic IV. Block-structured procedural languages Algol and Pascal. References:

Working with JavaScript

CS 314 Principles of Programming Languages

Transcription:

CSE 330 Test 1 (1 point) Spring 015 Multiple Choice. Write your answer to the LEFT of each problem. 3 points each 1. Lisp was invented at: A. IBM B. MIT C. Netscape D. Stanford. In C++, what operator is overloaded to provide simple input? A. & B. += C. << D. >> 3. Which language does not allow nesting functions? A. C B. Scheme C. JavaScript D. Pascal 4. (car (cdr (car (cdr '(a (b (c d e) f (g h) i)))))) will result in: A. ((g h i)) B. b C. (c d e) D. (g h i) 5. Regular expressions are convenient for defining what element of a programming language s definition? A. attributes B. binary strings C. terminals D. tokens 6. The Pascal equivalent of the C!= operator is: A.!= B. := C. <> D. == 7. Which of the following is not a JavaScript feature? A. first-class functions B. strong type checking C. event-driven execution D. integration with HTML 8. What is the result of (or 'a '(b c) 'd)? A. '(a (b c) d) B. 'd C. 'a D. #t E. #f 9. Pascal indicates the value to be returned from a function by using: A. a global variable B. a return statement C. a var parameter D. the name of the function 10. Which of the following allows anonymous functions? A. C B. Scheme C. PL/0 D. Pascal 11. If a value is second class, then it can be A. Assigned to a variable B. Returned from a function C. Passed as an argument D. All of the above 1. Short-circuit evaluation has historically been missing from which language? A. Scheme B. JavaScript C. Pascal D. C 13. It is considered good practice to assure that the second argument to cons is: A. an atom B. a function C. a list D. a number 14. Which of the following is not a characteristic of recursive descent? A. Error recovery B. Small lookahead C. Many precedence levels D. Top-down 15. What C++ language idiom avoids memory leaks? A. Built-in strings without null terminators B. Operator overloading C. Resource allocation is initialization (RAII) D. Templates 1. Write a Pascal function rangecount to count (and return) the number of values in a global integer array arr (with subscripts 1..lastSub) that are between two provided parameter values low and high. A value in arr should be counted only if it is not smaller than low and not larger than high. 18 points const lastsub=1000; var arr: array [1..lastSub] of integer;. Write a JavaScript function rangecount to count (and return) the number of values in a global integer array arr (with subscripts 1..lastSub) that are between two provided parameter values low and high. A value in arr should be counted only if it is not smaller than low and not larger than high. 18 points 3. Write a Scheme function rangecount to count (and return) the number of values in a simple integer list that are between two provided parameter values low and high. A value in the list should be counted only if it is not smaller than low and not larger than high. 18 points (rangecount '(1 4 3 5 4 3 6 7 3 1) 5) will return 8 CSE 330 Test Spring 015 Multiple Choice: 1. Write the letter of your answer on the line ( ) to the LEFT of each problem.. CIRCLED ANSWERS DO NOT COUNT. 3. 4 points each 1. For JavaScript, which expression always gives the same value as a b?

A.!(!a!b) B. a? b : a C. a? a : b D. b && a. Suppose the C declaration below occurs at global scope. Where would the space be allocated? int arr[10000]; A. static B. heap C. stack D. registers 3. Which of the following binding times is the earliest? A. compilation B. execution C. linking D. program writing 4. PL/0 uses static links to: A. Update the display table B. Return from a called procedure C. Place an integer on the stack D. Reference data 5. Which of the following has no mechanism for achieving block scope? A. C B. JavaScript C. Scheme D. Pascal 6. For which of the following pairs will JavaScript evaluate the === operator to false? A. 1, 1.0 B. 1, "1" C. '1', "1" D. 1.1, 1.1 7. Hoisting of declarations to the beginning of functions is associated with which language? A. C B. JavaScript C. Scheme D. Pascal 8. Jensen's Device implements a higher-order procedure using: A. call by value B. functional arguments C. static links D. call by name 9. Suppose a variable is referenced in a subroutine closure. Where is it stored? A. static B. heap C. stack D. registers 10. Which is true about the run-time cost of processing a thrown exception? A. It depends on the numbers of handlers and dynamic links encountered B. It is proportional to the number of static links followed C. It is proportional to the number of dynamic links followed D. It is always constant 1. Give equivalent C code (e.g. using if... else...) to demonstrate the short-circuit nature of C boolean operators. Do not use &&,, or! in your solution! Do not use work variables! Do not write functions or use return! (0 points) a. result = a < 10 && b >= 13; b. result = c <= 0 d > 17; c. result =!(e < 5 && f > 55)!(g < 66 && h>=77);

. Label the RTS locations (with PL/0 variable names) that are accessible at the call stop. (0 points) 3 0 var m; 1 1 procedure a(i); const k=1000; procedure b(j); 3 3 procedure c(k); 4 4 begin 5 if k<105 then 8 call c(k+) 15 else 15 call stop 16 end; 18 18 begin 19 if j<15 then call b(j+1) 9 else 9 begin 30 m:=i+j+k; 36 call c(101) 40 end 40 end; 41 41 begin 4 if i<5 then 45 call a(i+1) 5 else 5 call b(11) 57 end; 58 58 begin 59 call a(1) 63 end. 0 jmp 0 58 1 jmp 0 41 jmp 0 18 3 jmp 0 4 4 int 0 4 code for c 5 lod 0 3 k 6 lit 0 105 7 opr 0 10 < 8 jpc 0 16 9 int 0 3 push args(s) for c 10 lod 0 3 k 11 lit 0 1 opr 0 + 13 int 0-4 -(3+number of args) 14 cal 1 4 c 15 jmp 0 17 16 cal 3-7 stop 17 opr 0 0 return 18 int 0 4 code for b 19 lod 0 3 j 0 lit 0 15 1 opr 0 10 < jpc 0 30 3 int 0 3 push args(s) for b 4 lod 0 3 j 5 lit 0 1 6 opr 0 + 7 int 0-4 -(3+number of args) 8 cal 1 18 b 9 jmp 0 40 30 lod 1 3 i 31 lod 0 3 j 3 opr 0 + 33 lit 0 1000 34 opr 0 + 35 sto 5 m 36 int 0 3 push args(s) for c 37 lit 0 101 38 int 0-4 -(3+number of args) 39 cal 0 4 c 40 opr 0 0 return 41 int 0 4 code for a 4 lod 0 3 i 43 lit 0 5 44 opr 0 10 < 45 jpc 0 53 46 int 0 3 push args(s) for a 47 lod 0 3 i 48 lit 0 1 49 opr 0 + 50 int 0-4 -(3+number of args) 51 cal 1 41 a 5 jmp 0 57 53 int 0 3 push args(s) for b 54 lit 0 11 55 int 0-4 -(3+number of args) 56 cal 0 18 b 57 opr 0 0 return 58 int 0 6 code for driver 59 int 0 3 push args(s) for a 60 lit 0 1 61 int 0-4 -(3+number of args) 6 cal 0 41 a 63 opr 0 0 return b=55 p=17 58 105 57 15 ret adr 56 51 d.l. 55 43 s.l. 54 103 53 15 ret adr 5 47 d.l. 51 43 s.l. 50 101 49 40 ret adr 48 43 d.l. 47 43 s.l. 46 15 45 9 ret adr 44 39 d.l. 43 3 s.l. 4 14 41 9 ret adr 40 35 d.l. 39 3 s.l. 38 13 37 9 ret adr 36 31 d.l. 35 3 s.l. 34 1 33 9 ret adr 3 7 d.l. 31 3 s.l. 30 11 9 57 ret adr 8 3 d.l. 7 3 s.l. 6 5 5 5 ret adr 4 19 d.l. 3 1 s.l. 4 1 5 ret adr 0 15 d.l. 19 1 s.l. 18 3 17 5 ret adr 16 11 d.l. 15 1 s.l. 14 13 5 ret adr 1 7 d.l. 11 1 s.l. 10 1 9 63 ret adr 8 1 d.l. 7 1 s.l. 6 100 5-999999 4-999999 3 0 ret adr 0 d.l. 1 0 s.l.

3. Give beautiful Scheme code for a function levels that will replace each atom in its single argument by its nesting level, i.e. the number of parentheses it is nested within. (0 points) (levels 'a) (levels '(a)) (levels '((((a)) b) c)) (levels '(1 (0 (3 (4 40) 3) ) 1)) (levels '(11 ( (3 (4 () 4) 3) ) 15 ())) would have output: 0 '(1) '((((4)) ) 1) '(1 ( (3 (4 4) 3) ) 1) '(1 ( (3 (4 () 4) 3) ) 1 ()) CSE 330/5307 Test 3 Spring 015 Multiple Choice: 1. Write the letter of your answer on the line ( ) to the LEFT of each problem.. CIRCLED ANSWERS DO NOT COUNT. 3. 4 points each 1. Information hiding is associated with? A. prototypal inheritance B. data abstraction C. Liskov Substitution Principle D. garbage collection. The diamond problem is an issue with A. continutations B. multiple inheritance C. interfaces D. polymorphism 3. A new property may be added to a JavaScript object using: A. assignment B. new C. Object.create() D. prototypal inheritance 4. Continuations could be viewed as being a generalization of: A. activation records B. combinator C. exceptions D. functions 5. In JavaScript, the result of [0,[1,],"13",3].length will be: A. undefined B. 3 C. 4 D. 5 6. Generational garbage collection is a generalization of: A. mark-and-sweep B. reference counts C. Schorr-Waite D. stop-and-copy 7. Indicate the value of ((lambda (x y) (x (x y))) (lambda (z) (- 5 z)) 10) A. 5 B. 10 C. 15 D. 0 8. What will appear on the console for the JavaScript code below? arr=[]; arr[10]=1; console.log(arr["10"]); A. exception B. 5 C. 1 D. undefined 9. Type inference is associated with which language: A. C B. JavaScript C. ML D. Pascal 10. The Y combinator is useful for: A. anonymous functions B. continuations C. threads D. unary functions 1. What is the result of executing this Scheme code? (5 points) (define (f x y) (* 5 (+ x y))) ((lambda (y x z) (f y (x y z))) 10 + 3). What appears on the console for the code below? (10 points)

a={b: 5, c: 6 b=object.create(a); b.c=7; c=object.create(b); c.d=8; delete c.c; delete b.c; console.log(c.b); console.log(c.c); console.log(c.d); console.log(a.x); 3. What appears on the console for the code below? (15 points) var makecountergroup = function() { var counter=0; return { newsub: function (initval) { var subcounter=0; var funcs = { reset: function() { counter=counter-subcounter+initval; subcounter=initval; up: function(val) { subcounter+=val; counter+=val; down: function(val) { subcounter-=val; counter-=val; value: function() { return subcounter; } funcs.reset(); return funcs; value: function() { return counter; } 5 var a=makecountergroup(); var b=makecountergroup(); var c=a.newsub(100); var d=a.newsub(00); var e=b.newsub(300); var f=b.newsub(400); c.up(50); f.down(50); e.reset(); console.log(a.value()); console.log(b.value()); console.log(c.value()); console.log(d.value()); console.log(e.value()); console.log(f.value()); 4. Suppose a Pascal array is to be stored starting at location 0000 and is declared: c: array[8..70,19..33,5..9] of integer; If one integer takes two bytes, what is the location of c[44,,7]? (15 points) 5. Suppose the atoms in an S-expression are integers. Write a Scheme function prefix to replace each atom with the sum of all atoms that have appeared to its left. (15 points) > (prefix '(1 3 4 5)) '(0 1 3 6 10) > (prefix '(1 ( 3) (4 () ((((5))))))) '(0 (1 3) (6 () ((((10)))))) > (prefix '((10000) (000 (((300)))) (40 5) (0))) '((0) (10000 (((1000)))) (1300 1340) (1345)) > (prefix '((((134))))) '((((0))))