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

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.

low and not larger than high. 18 points

Principles of Programming Languages [PLP-2015] Detailed Syllabus

Short Notes of CS201

CS201 - Introduction to Programming Glossary By

Functional Programming. Pure Functional Languages

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

Functional Programming. Pure Functional Languages

CS 415 Midterm Exam Spring SOLUTION

Introduction to Programming Using Java (98-388)

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING

G Programming Languages - Fall 2012

Functional Programming. Pure Functional Programming

Lecture 09: Data Abstraction ++ Parsing is the process of translating a sequence of characters (a string) into an abstract syntax tree.

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

CSE 3302 Notes 6: Data Types

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

NOTE: Answer ANY FOUR of the following 6 sections:

UMBC CMSC 331 Final Exam

CMSC 331 Final Exam Section 0201 December 18, 2000

Interview Questions of C++

CSE 3302 Notes 7: Control Abstraction

Functional Programming. Big Picture. Design of Programming Languages

CSE 413 Languages & Implementation. Hal Perkins Winter 2019 Structs, Implementing Languages (credits: Dan Grossman, CSE 341)

CPSC 3740 Programming Languages University of Lethbridge. Data Types

CS 360 Programming Languages Interpreters

Final-Term Papers Solved MCQS with Reference

St. MARTIN S ENGINEERING COLLEGE Dhulapally, Secunderabad

Comp 333: Concepts of Programming Languages Fall 2016

Lecture #24: Programming Languages and Programs

About the Authors... iii Introduction... xvii. Chapter 1: System Software... 1

CS 415 Midterm Exam Spring 2002

CS 415 Midterm Exam Fall 2003

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

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

PROGRAMMAZIONE I A.A. 2017/2018

Topics Covered Thus Far. CMSC 330: Organization of Programming Languages. Language Features Covered Thus Far. Programming Languages Revisited

STRUCTURING OF PROGRAM

Programming Languages (PL)

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

C++ for System Developers with Design Pattern

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

CMSC 330: Organization of Programming Languages

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

CSCE 314 Programming Languages. Type System

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

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

Semantic Analysis. Outline. The role of semantic analysis in a compiler. Scope. Types. Where we are. The Compiler Front-End

Semantic Analysis. Outline. The role of semantic analysis in a compiler. Scope. Types. Where we are. The Compiler so far

Organization of Programming Languages CS3200/5200N. Lecture 11

Compilers. Type checking. Yannis Smaragdakis, U. Athens (original slides by Sam

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

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

Control in Sequential Languages

Weiss Chapter 1 terminology (parenthesized numbers are page numbers)

Project 2: Scheme Interpreter

CSE413 Midterm. Question Max Points Total 100

CHOICE BASED CREDIT SYSTEM (With effect from )

Time : 1 Hour Max Marks : 30

The role of semantic analysis in a compiler

The Compiler So Far. CSC 4181 Compiler Construction. Semantic Analysis. Beyond Syntax. Goals of a Semantic Analyzer.

JavaScript: Sort of a Big Deal,

Symbol Tables. ASU Textbook Chapter 7.6, 6.5 and 6.3. Tsan-sheng Hsu.

The Foundation of C++: The C Subset An Overview of C p. 3 The Origins and History of C p. 4 C Is a Middle-Level Language p. 5 C Is a Structured

CS 314 Principles of Programming Languages

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

AP COMPUTER SCIENCE JAVA CONCEPTS IV: RESERVED WORDS

COMP 181. Agenda. Midterm topics. Today: type checking. Purpose of types. Type errors. Type checking

Implementing Subprograms

Introducing C++ to Java Programmers

G Programming Languages - Fall 2012

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

VALLIAMMAI ENGINEERING COLLEGE

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

Chapter 3:: Names, Scopes, and Bindings (cont.)

Final exam. Final exam will be 12 problems, drop any 2. Cumulative up to and including week 14 (emphasis on weeks 9-14: classes & pointers)

Chapter 3:: Names, Scopes, and Bindings (cont.)

Programming Languages

SEMANTIC ANALYSIS TYPES AND DECLARATIONS

CS

Concepts Introduced in Chapter 7

Semantic Analysis and Type Checking

Review of the C Programming Language

UMBC CMSC 331 Final Exam

CS 314 Principles of Programming Languages

Chapter 3 (part 3) Describing Syntax and Semantics

An Introduction to C++

Get Unique study materials from

WA1278 Introduction to Java Using Eclipse

Functions and Recursion. Dr. Philip Cannata 1

CS 314 Principles of Programming Languages

Scheme Basics > (butfirst '(help!)) ()

CSE P 501 Compilers. Static Semantics Hal Perkins Winter /22/ Hal Perkins & UW CSE I-1

Pace University. Fundamental Concepts of CS121 1

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

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

CMSC 4023 Chapter 9. Fundamentals of Subprograms Introduction

Microsoft. Microsoft Visual C# Step by Step. John Sharp

Absolute C++ Walter Savitch

Transcription:

Test 1 Multiple Choice. Write your answer to the LEFT of each problem. 4 points each 1. Which celebrity has not received an ACM Turing Award? A. Alan Kay B. John McCarthy C. Dennis Ritchie D. Bjarne Stroustrup 2. Short-circuit evaluation has historically been missing from which language? A. C B. JavaScript C. Pascal D. Scheme 3. Which of the following is not emphasized in Elements of Programming? A. Behavioral vs. representational equality B. Class/subclass hierarchies C. Decomposition and rigorous design decisions D. Separation of algorithms and data structures 4. 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 5. Which language has the smallest set of first class objects? A. C++ B. JavaScript C. PL/0 D. Scheme 6. For C++, what language feature is preferred over macros? A. Built-in strings without null terminators B. Operator overloading C. Resource allocation is initialization (RAII) D. Templates 7. Which of the following is true regarding attribute grammars? A. Inherited attributes carry information up the parse tree B. Synthesized attributes carry information down the parse tree C. They can represent context-sensitive information D. They cannot capture the information that usually goes in symbol tables 8. Lab 1 required modifying which part of PL/0? A. Hand-written scanner B. Railroad diagrams C. Recursive-descent parser/code generator D. Stack-based interpreter 9. The necessity for programming languages to evolve is advocated by: A. Edsger Dijkstra B. John McCarthy C. Guy Steele D. Bjarne Stroustrup 10. Many development organizations require the use of { and when coding control structures in a C derivative language. This avoids which issue? A. dangling else B. subscripts out of range C. unmatched delimiters D. exceptions 11. Which language does not allow nesting functions? A. C++ B. Scheme C. JavaScript D. Pascal 12. What is the result of (cdr (cons (car '(a (b c (d e)) f g)) (cdr '((h i) j (k l)))))? A. '(j (k l)) B. '(a j (k l)) C. '((b c (d e)) f g) D. '(h i) 13. What is the result of (and 'a '(b c) 'd)? A. '(a (b c) d) B. 'd C. 'a D. #t 14. Regular expressions are convenient for defining what part of a programming language? A. attributes B. binary strings C. tokens D. terminals 15. In C++, what operator is overloaded to provide simple output? A. & B. += C. << D. cout 1. Give a Scheme predicate test1? that indicates whether its three integer parameters are all positive. 10 points The results for a few specific cases below are indicated. (test1? 1 2 3) should return #t (test1? 0-1 -2) should return #f (test1? 3 2 0) should return #f 2. Give a JavaScript function test1 that indicates whether its three integer parameters are all positive. The result should be returned to the caller. 10 points 3. Give a JavaScript function allequal that takes an array of integers as its only argument and returns a Boolean value to indicate whether all of the values are the same. 20 points 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

allequal ([2]) should return true allequal ([]) should return true allequal ([-1,1,1,1]) should return false Test 2 Multiple Choice. Write your answer to the LEFT of each problem. 5 points each 1. Which is true about the run-time cost of processing a thrown exception? A. It is proportional to the number of dynamic links followed B. It is always constant C. It depends on the numbers of handlers and dynamic links encountered D. It is proportional to the number of static links followed 2. 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. 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 4. Suppose a variable is referenced in a subroutine closure. Where is it stored? A. static B. heap C. stack D. registers 5. The notion of l-value and r-value is associated with which PL construct? A. assignment B. iteration C. recursion D. selection 6. Duff s device involves which PL construct? A. C union B. C switch C. Java switch D. C varargs 7. Which language does not allow nesting functions? A. C B. Scheme C. JavaScript D. Pascal 8. 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 9. Hoisting of declarations to the beginning of functions is associated with which language? A. C B. JavaScript C. Scheme D. Pascal 10. Jensen's Device implements a higher-order procedure using: A. call by name B. functional arguments C. static links D. call by value 11. C++ controls name conflicts by using: A. & B. exception hierarchies C. namespaces D. overloading 12. Which of the following binding times is the latest? A. compilation B. execution C. linking D. program writing 1. Give equivalent inline 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 use return! (20 points) a. result = a > 10 && b < 13; b. result = c > 20 d <= 17; c. result =!(e > 25 f < 55) && g > 66; 2. Write a Scheme function (along with helper functions) that takes an unordered list of integers (with at least one atom) and moves the smallest value to the end of the list. If the smallest value appears several times, then the last occurence (going left-to-right) will be the one moved to the end. 20 points > (smalltoend '(1 2 2 1 2 2 1 2)) '(1 2 2 1 2 2 2 1) > (smalltoend '(11 22 22 11 22 22 33 22 33)) '(11 22 22 22 22 33 22 33 11) > (smalltoend '(1)) '(1) > (smalltoend '(1 2 3 4)) '(2 3 4 1) > (smalltoend '(4 3 2 0 2 3 4)) '(4 3 2 2 3 4 0) Test 3 Multiple Choice. Write your answer to the LEFT of each problem. 4 points each 1. The notion of a mixin is associated with? 2

A. ML B. C++ templates C. JavaScript dynamic typing D. multiple inheritance 2. Existential types for abstract data types allow multiple A. operations B. implementations C. interfaces D. inheritance 3. A new property may be added to a JavaScript object using: A. assignment B. new C. Object.create() D. prototypal inheritance 4. The for.. in construct is used to: A. enumerate array elements that are not undefined B. enumerate properties C. test a subclass/superclass relationship D. iterate over an integer subrange 5. Which of the following JavaScript objects does not have a length? A. arrays B. functions C. numbers D. strings 6. Stop-and-copy is an example of: A. reference counts B. garbage collection C. deep comparison D. run-time stack implementation 7. Indicate the value of ((lambda (x y) (x (x y))) (lambda (z) (+ 5 z)) 10) A. 5 B. 10 C. 15 D. 20 8. Which of the following will be treated like false (In JavaScript)? A. 5 B. undefined C. "else" D. "false" 9. Dynamic binding in a statically-typed language is exemplified by A. JavaScript B. Scheme C. Java D. Pascal 10. The state of a Scheme computation may be saved as: A. a closure B. a continuation C. a combinator D. a thread 1. What is the result of executing this Scheme code? (10 points) (define (f x y) (* 5 (+ x y))) ((lambda (y x z) (f y (x y z))) 10 * 3) 2. What appears on the console for the code below? (10 points) function g(x) { a: function (y) { x.push(y); b: function () { return x.pop(); c: function () { return x.length; d: function(sub,val) { x[sub]=val; ; var a=g([5,3,2,4]); a.d(3,7); console.log(a.b()); a.a(11); a.a(22); a.d("romo",9); console.log(a.c()); console.log(a.x); 3. The JavaScript code below was provided along with lab 4. Carefully indicate the additional code to give each of the three classes a min() method to give the minimum value for that class (20 points) 3

4 a. For the pointclass, the minimum is the smallest v provided to the constructor b. For the intervalclass, the minimum is the smallest l provided to the constructor c. For the rootclass, the minimum is the smallest value over the two subclasses var rootclass,intervalclass,pointclass; rootclass=(function () { // just counts total number of instances var instancecount=0; add1: function () {instancecount++; count: function () {return instancecount; ; )(); intervalclass=object.create(rootclass); var wrki=(function () { var instancecount=0; // access in closure )(); ; construct: function (l,r) { // Each instance has intervalclass as prototype if (l>r) { lab4output.innerhtml+= "invalid call to construct "+l+" "+r; throw "invalid call to construct "+l+" "+r; this.add1(); // for total number of objects instancecount++; var obj=object.create(intervalclass); obj.get=function () { return obj; count: function () { intervalclass.construct=wrki.construct; intervalclass.count=wrki.count; intervalclass.inside=function (x) { left:l,right:r; ; return instancecount; var work=this.get(); return work.left<=x && x<=work.right; ; intervalclass.measure=function () {

var work=this.get(); return work.right-work.left; ; pointclass=object.create(rootclass); var wrkp=(function () { var instancecount=0; // access in closure )(); ; construct: function (v) { // Each instance has intervalclass as prototype this.add1(); // for total number of objects instancecount++; var obj=object.create(pointclass); obj.get=function () { return obj; count: function () { pointclass.construct=wrkp.construct; pointclass.count=wrkp.count; pointclass.inside=function (x) { return v; ; return instancecount; return this.get()==x; pointclass.measure=function () {return 0;; var a=intervalclass.construct(20,30); var b=intervalclass.construct(25,35); var c=intervalclass.construct(7,90); var d=pointclass.construct(100); var e=pointclass.construct(50); var f=pointclass.construct(70); console.log(rootclass.min()); // Gives 7 console.log(intervalclass.min()) // Gives 7 console.log(pointclass.min()); // Gives 50 4. Suppose a Pascal array is to be stored starting at location 20000 and is declared: c: array[24..70,20..33,5..8] of integer; If one integer takes two bytes, what is the location of c[44,22,7]? (20 points) 5